最近写项目发现导入Swagger2依赖会报错Failed to start bean ‘documentationPluginsBootstrapper‘

这个错误是由Springfox的一个bug引起,解决这个问题的方式有多种,最简单的方法就是在配置文件yml中添加spring.mvc.pathmath.matching-strategy: ant_path_matcher即可解决这个问题
同样也可以在SwaggerConfig配置类中修改,如下:

@Configuration
@EnableSwagger2
public class SwaggerConfig extends WebMvcConfigurationSupport {

    /*
     * No mapping for GET /emge-api/swagger-ui.html
     * documentationPluginsBootstrapper
     *
     * */
    @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);
    }

}

SwaggerConfig继承WebMvcConfigurationSupport并实现其方法即可解决报错问题

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐