diff --git a/gradle/dependencies.gradle b/gradle/dependencies.gradle index 8d7b022..608f0d0 100644 --- a/gradle/dependencies.gradle +++ b/gradle/dependencies.gradle @@ -12,12 +12,10 @@ ext { "org.springframework:spring-core:$springVersion", "org.springframework:spring-web:$springVersion", "org.springframework:spring-webmvc:$springVersion" - ], springBoot : [ "org.springframework.boot:spring-boot-starter-web:${springBootVersion}" ], - springfoxPetstore : [ "io.springfox:springfox-petstore:2.10.5" ], @@ -26,9 +24,13 @@ ext { "io.springfox:springfox-spring-webmvc:${springfoxVersion}", "io.springfox:springfox-swagger2:${springfoxVersion}" ], + springfoxOpenApi : [ + "io.springfox:springfox-spring-web:${springfoxVersion}", + "io.springfox:springfox-spring-webmvc:${springfoxVersion}", + "io.springfox:springfox-oas:${springfoxVersion}" + ], springfoxSwaggerUi: [ "io.springfox:springfox-swagger-ui:${springfoxVersion}" -// "io.springfox.ui:springfox-swagger-ui-rfc6570:1.0.0" ], jackson : [ "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}", diff --git a/spring-java-swagger/build.gradle b/spring-java-swagger/build.gradle index 1bc6385..53a6287 100644 --- a/spring-java-swagger/build.gradle +++ b/spring-java-swagger/build.gradle @@ -7,7 +7,7 @@ apply plugin: 'war' dependencies { compile libs.spring compile libs.jackson - compile libs.springfoxSwagger2 + compile libs.springfoxOpenApi compile libs.springfoxSwaggerUi compile 'org.slf4j:slf4j-simple:1.7.30' testCompile libs.test diff --git a/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ApplicationConfiguration.java b/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/AppConfiguration.java similarity index 62% rename from spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ApplicationConfiguration.java rename to spring-java-swagger/src/main/java/springfoxdemo/java/swagger/AppConfiguration.java index ae9016f..f87d1f2 100644 --- a/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ApplicationConfiguration.java +++ b/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/AppConfiguration.java @@ -3,11 +3,11 @@ import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.config.annotation.EnableWebMvc; -import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc; +import springfox.documentation.oas.annotations.EnableOpenApi; @Configuration -@ComponentScan @EnableWebMvc -@EnableSwagger2WebMvc -public class ApplicationConfiguration { +@ComponentScan("springfoxdemo.java.swagger") +@EnableOpenApi +public class AppConfiguration { } diff --git a/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ApplicationInitializer.java b/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ServletInitializer.java similarity index 59% rename from spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ApplicationInitializer.java rename to spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ServletInitializer.java index 09a1108..8583293 100644 --- a/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ApplicationInitializer.java +++ b/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/ServletInitializer.java @@ -2,19 +2,21 @@ import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer; -public class ApplicationInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { - @Override - protected Class[] getRootConfigClasses() { - return new Class[]{ApplicationConfiguration.class}; - } +public class ServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer { @Override protected Class[] getServletConfigClasses() { - return new Class[]{SpringConfig.class}; + return new Class[] { AppConfiguration.class }; } @Override protected String[] getServletMappings() { - return new String[]{"/*"}; + return new String[] { "/" }; + } + + @Override + protected Class[] getRootConfigClasses() { + return null; } + } diff --git a/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/SpringConfig.java b/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/SpringConfig.java index 42c15a3..50402fe 100644 --- a/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/SpringConfig.java +++ b/spring-java-swagger/src/main/java/springfoxdemo/java/swagger/SpringConfig.java @@ -1,17 +1,23 @@ package springfoxdemo.java.swagger; -import org.springframework.context.annotation.Configuration; +import org.springframework.stereotype.Component; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; +import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +@Component public class SpringConfig implements WebMvcConfigurer { - @Override public void addResourceHandlers(ResourceHandlerRegistry registry) { - registry.addResourceHandler("swagger-ui.html") - .addResourceLocations("classpath:/META-INF/resources/"); + registry. + addResourceHandler("/swagger-ui/**") + .addResourceLocations("classpath:/META-INF/resources/webjars/springfox-swagger-ui/") + .resourceChain(false); + } - registry.addResourceHandler("/webjars/**") - .addResourceLocations("classpath:/META-INF/resources/webjars/"); + @Override + public void addViewControllers(ViewControllerRegistry registry) { + registry.addViewController("/swagger-ui/") + .setViewName("forward:" + "/swagger-ui/index.html"); } }