Home > Java > Java Tutorial > body text

How to solve the 404 error when configuring SwaggerUI in SpringBoot

WBOY
Release: 2023-05-12 18:28:06
forward
2712 people have browsed it

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:


      io.springfox
      springfox-swagger-ui
      2.2.2
    

    
      io.springfox
      springfox-swagger2
      2.2.2
Copy after login

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();
  }
}
Copy after login

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
Copy after login

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/
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!