最近写项目发现导入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并实现其方法即可解决报错问题
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)