Springboot swagger url shows WhiteLabel Error page

gradle, java, spring, spring-boot

Solution

For the new Springfox version(3.0.0) you need to do something different

In pom.xml add the following dependency

*

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

instead of two for `<artifactId>springfox-swagger2</artifactId>` and `<artifactId>springfox-swagger-ui</artifactId>`

and access ../swagger-ui/ instead of ../swagger-ui.html

Problem

Here is my code: I am getting all the values from application.properties file SwaggerConfig.java ``` @Configuration @EnableSwagger2 @Profile("!prod") @PropertySource(value = { "classpath:application.properties" }) public class SwaggerConfig { @Value("${swagger.api.title}") private String title; @Value("${swagger.api.description}") private String description; @Value("${swagger.api.termsOfServiceUrl}") private String termsOfServiceUrl; @Value("${swagger.api.version}") private String version; @Value("${swagger.api.controller.basepackage}") private String basePackage; @Bean public Docket postMatchApi() { return new Docket(DocumentationType.SWAGGER_2).select().apis(RequestHandlerSelectors.basePackage(basePackage)) .paths(PathSelectors.ant("/**")).build().apiInfo(metaData()); } private ApiInfo metaData() { return new ApiInfoBuilder().title(title).description(description).termsOfServiceUrl(termsOfServiceUrl) .version(version).build(); } ``` Here is my springboot initializer: ``` @SpringBootApplication @ComponentScan(basePackages = { "com.example.demo" }) @ComponentScan(basePackageClasses = {AppInitializer.class, SwaggerConfig.class}) @EnableAsync @EnableRetry public class AppInitializer{ public static void main(String[] args) { SpringApplication.run(AppInitializer.class, args); } } ``` ServletInitializer.java ``` public class ServletInitializer extends SpringBootServletInitializer implements WebApplicationInitializer { @Override protected SpringApplicationBuilder configure(SpringApplicationBuilder application) { return application.sources(PostMatchAppInitializer.class); } } ``` The log says it is mapped: ``` [INFO ] 2018-01-17 16:46:37.055 [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[],methods=[POST],consumes=[application/json],produces=[application/json]}" onto public <T> org.springframework.http.ResponseEntity<?> com.,org.springframework.validation.BindingResult) throws java.lang.Exception [INFO ] 2018-01-17 16:46:37.055 [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/v2/api-docs],methods=[GET],produces=[application/json || application/hal+json]}" onto public org.springframework.http.ResponseEntity<springfox.documentation.spring.web.json.Json> springfox.documentation.swagger2.web.Swagger2Controller.getDocumentation(java.lang.String,javax.servlet.http.HttpServletRequest) [INFO ] 2018-01-17 16:46:37.055 [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources/configuration/ui]}" onto org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.UiConfiguration> springfox.documentation.swagger.web.ApiResourceController.uiConfiguration() [INFO ] 2018-01-17 16:46:37.055 [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources]}" onto org.springframework.http.ResponseEntity<java.util.List<springfox.documentation.swagger.web.SwaggerResource>> springfox.documentation.swagger.web.ApiResourceController.swaggerResources() [INFO ] 2018-01-17 16:46:37.055 [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/swagger-resources/configuration/security]}" onto org.springframework.http.ResponseEntity<springfox.documentation.swagger.web.SecurityConfiguration> springfox.documentation.swagger.web.ApiResourceController.securityConfiguration() [INFO ] 2018-01-17 16:46:37.055 [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error]}" onto public org.springframework.http.ResponseEntity<java.util.Map<java.lang.String, java.lang.Object>> org.springframework.boot.autoconfigure.web.BasicErrorController.error(javax.servlet.http.HttpServletRequest) [INFO ] 2018-01-17 16:46:37.071 [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped "{[/error],produces=[text/html]}" onto public org.springframework.web.servlet.ModelAndView org.springframework.boot.autoconfigure.web.BasicErrorController.errorHtml(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse) [INFO ] 2018-01-17 16:46:37.227 [restartedMain] o.s.w.s.m.m.a.RequestMappingHandlerAdapter - Looking for @ControllerAdvice: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext@5e89f6: startup date [Wed Jan 17 16:46:34 CST 2018]; root of context hierarchy ``` This is the error that i get: ``` [WARN ] 2018-01-17 16:46:42.217 [http-nio-8082-exec-1] o.s.w.s.PageNotFound - No mapping found for HTTP request with URI [/example/swagger-ui.html] in DispatcherServlet with name 'dispatcherServlet' ```

Original source

Related problems