SpringBoot configures SwaggerUI to access 404 small pit.
When learning SpringBoot to build Restful API, I encountered a small pitfall, which was inaccessible when configuring Swagger UI.
First, add Swagger's dependencies to your own pom file, as shown below:
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.2.2</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.2.2</version></dependency>
Then create a new SwaggerConfig class:
Configuration@EnableSwagger2public class SwaggerConfig { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.nightowl")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("NightOwl RESTful APIs") .description("Follow me http://hwangfantasy.github.io/") .termsOfServiceUrl("http://hwangfantasy.github.io/") .contact("Senior Yan Yi") .version("1.0") .build(); }} Finally, add a series of API annotations to your own controller. In fact, it can be used normally without adding API annotations.
Finally, you can see the swagger page in localhost:8080/swagger-ui.html.
But the key is here. The first time I configured it according to this method, I prompted the following error:
Whitelabel Error PageThis application has no explicit mapping for /error, so you are seeing this as a fallback.Thu Nov 24 19:57:13 CST 2016There was an unexpected error (type=Not Found, status=404).No message available
But I had no problem with reconfiguring a new project, so I thought that there must be some configurations in my project that conflict with swagger.
Finally found in application.properties
spring.resources.static-locations=classpath:/static/
Comment this line and access it.
The above is all the content of this article. I hope it will be helpful to everyone's learning and I hope everyone will support Wulin.com more.