Home >Java >javaTutorial >How to solve the 404 error when configuring SwaggerUI in SpringBoot
SpringBoot configures SwaggerUI to access the 404 pit.
When I was learning SpringBoot to build Restful API, I encountered a small pit, which was inaccessible when configuring Swagger UI.
First add the Swagger dependency to your 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 @EnableSwagger2 public 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("关注我 http://hwangfantasy.github.io/") .termsOfServiceUrl("http://hwangfantasy.github.io/") .contact("颜艺学长") .version("1.0") .build(); } }
Finally add it to your Controller The previous series of API annotations are enough. In fact, it can be used normally without adding API annotations.
Finally, visit localhost:8080/swagger-ui.html to see the swagger page.
But here comes the key. The first time I configured it in this way, I got the following error:
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Thu Nov 24 19:57:13 CST 2016 There was an unexpected error (type=Not Found, status=404). No message available
But I created a new project and reconfigured it without any problems, so I thought of it in my own project. There must be some configuration that conflicts with swagger.
Finally found that commenting out the
spring.resources.static-locations=classpath:/static/
line in application.properties can be accessed.
The above is the detailed content of How to solve the 404 error when configuring SwaggerUI in SpringBoot. For more information, please follow other related articles on the PHP Chinese website!