swagger无法访问UI页面No mapping for GET /swagger-ui.html

检查项目是否用实现WebMvcConfigurer相关接口

如下,发现WebMvcConfig类实现了WebMvcConfigurer接口,导致访问不了,注释即可

//@Configuration
//@EnableWebMvc //全面接管
//public class WebMvcConfig implements WebMvcConfigurer {
//    @Override
//    public void addViewControllers(ViewControllerRegistry registry) {
//        // 浏览器发送/test , 就会跳转到test页面;
//        //registry.addViewController("/test").setViewName("user/detail");
//    }
//}

或配置规则

@Configuration
public class WebMvcConfigurer extends WebMvcConfigurationSupport {

    /**
     * 发现如果继承了WebMvcConfigurationSupport,则在yml中配置的相关内容会失效。 需要重新指定静态资源
     *
     * @param registry
     */
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**").addResourceLocations(
                "classpath:/static/");
        registry.addResourceHandler("swagger-ui.html").addResourceLocations(
                "classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations(
                "classpath:/META-INF/resources/webjars/");
        super.addResourceHandlers(registry);
    }
}

版权声明:本文为weixin_44371237原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。