【springboot 中集成 knife4j 时,报错 No mapping for GET /doc.html】

出现这种情况可能是项目中含有继承WebMvcConfigurationSupport的类,这会导致 swagger 配置失效。

解决方法,继承WebMvcConfigurationSupport下重写addResourceHandlers方法

 @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html")
                .addResourceLocations("classpath:/META-INF/resources/");

        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

 重新运行,完美解决

你可能感兴趣的:(遇到的坑,spring,boot,html,java)