package com.bezkoder.spring.swagger.config; import java.util.List; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.info.Contact; import io.swagger.v3.oas.models.info.Info; import io.swagger.v3.oas.models.info.License; import io.swagger.v3.oas.models.servers.Server; @Configuration public class OpenAPIConfig { @Value("${bezkoder.openapi.dev-url}") private String devUrl; @Value("${bezkoder.openapi.prod-url}") private String prodUrl; @Bean public OpenAPI myOpenAPI() { Server devServer = new Server(); devServer.setUrl(devUrl); devServer.setDescription("Server URL in Development environment"); Server prodServer = new Server(); prodServer.setUrl(prodUrl); prodServer.setDescription("Server URL in Production environment"); Contact contact = new Contact(); contact.setEmail("bezkoder@gmail.com"); contact.setName("BezKoder"); contact.setUrl("https://www.bezkoder.com"); License mitLicense = new License().name("MIT License").url("https://choosealicense.com/licenses/mit/"); Info info = new Info() .title("Tutorial Management API") .version("1.0") .contact(contact) .description("This API exposes endpoints to manage tutorials.").termsOfService("https://www.bezkoder.com/terms") .license(mitLicense); return new OpenAPI().info(info).servers(List.of(devServer, prodServer)); } }Swagger is accessible via a URL - http://localhost:8080/api/swagger-ui/index.html <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency><dependency> <groupId>io.springfox</groupId> <artifactId>springfox-boot-starter</artifactId> <version>3.0.0</version> </dependency><dependency> <groupId>org.springdoc</groupId> <artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> <version>2.0.2</version> </dependency>@Override public void addResourceHandlers(ResourceHandlerRegistry registry) { registry.addResourceHandler("swagger-ui.html") .addResourceLocations("classpath:/META-INF/resources/"); registry.addResourceHandler("/webjars/**") .addResourceLocations("classpath:/META-INF/resources/webjars/"); }<!-- Spring Fox Dependencies --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>