Get the App
SLTechnology News&Howtos  ›  Development  › 

How to solve the error of SpringBoot configuring SwaggerUI access 404

Shulou Source: shulou.com Published: 2022-06-01 00:45:41 09月21日 Update

This article "SpringBoot configuration SwaggerUI access error how to solve" most people do not understand, so the editor summarizes the following content, detailed, clear steps, with a certain reference value, I hope you can get something after reading this article, let's take a look at this "SpringBoot configuration SwaggerUI access error how to solve" article.

SpringBoot configures SwaggerUI to access the pit of 404.

I encountered a small pit while learning SpringBoot to build Restful API, and I couldn't access it when configuring Swagger UI.

First, add the Swagger dependency to your pom file, as shown below:

Io.springfox springfox-swagger-ui 2.2.2 io.springfox springfox-swagger2 2.2.2

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")) .build () } private ApiInfo apiInfo () {return new ApiInfoBuilder () .title ("NightOwl RESTful APIs") .description ("follow me http://hwangfantasy.github.io/") .termsOfServiceUrl (" http://hwangfantasy.github.io/") .contact ") .version (" 1.0") .build ();}}

Finally, you can add a series of API annotations to your Controller, but you can use them normally without adding API annotations.

Finally, you can see the swagger page by visiting localhost:8080/swagger-ui.html.

But here's the point. The first time I configured it in this way, 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 didn't have any problems with reconfiguring a new project, so I thought of which configurations in my project must conflict with swagger.

Finally, it is found that in application.properties

Spring.resources.static-locations=classpath:/static/

This line is commented out and you can access it.

The above is about "SpringBoot configuration SwaggerUI access 404 error how to solve" this article, I believe we all have a certain understanding, I hope the editor to share the content to help you, if you want to know more related knowledge, please pay attention to the industry information channel.

Tags: Configuration content errors pits articles times notes knowledge articles projects China plus one line value key most seniors that is files methods more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Redmi NVidia MariaDB Docker