Swagger-ui.html Open Error: There was an unexpected error (type=Not Found, status=404)

After starting the springboot project, the following error will be reported if the swagger page cannot be opened:

after checking the data, it is found that webmvcconfig custom inherits webmvcconfigureradapter in the code, which causes the configuration related contents in the configuration file to be invalid, and the static resources need to be specified again

@Configuration
public class WebMvcConfig extends WebMvcConfigurerAdapter {
    @Value("${file.front-end.path}")
    private String fePath;

    @Value("${file.up-down-load.static-path}")
    private String udlPath;

    /**
     * Static resource handling
     **/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations(fePath,udlPath);
    }

    /**
     * Front and back-end separation to solve cross-domain problems
     **/
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedMethods("*")
                .allowedOrigins("*")
                .allowCredentials(true);
    }

    //Allow multiple request addresses with extra slashes e.g. /msg/list   //msg/list
    @Bean
    public HttpFirewall httpFirewall() {
        return new DefaultHttpFirewall();
    }


}

It is amended as follows:

 /**
     * Static resource handling
     **/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations(fePath,udlPath);
        // Add access to swagger pages
        registry.addResourceHandler("swagger-ui.html").addResourceLocations(
                "classpath:/META-INF/resources/");
    }

Login again, access success


Read More: