SpringBoot2.6.x 与 Swagger3 兼容问题及解决方法
更新时间:2025年03月21日 11:30:03 作者:大大怪将军~~~~
文章介绍了Spring Boot 2.6.x与Swagger 3兼容性问题的解决方法,如果项目中未引入spring-boot-starter-actuator,则在yml文件中加入相关配置,反之,需要添加其他配置,感兴趣的朋友一起看看吧
报错:
Failed to start bean 'documentationPluginsBootstrapper'; nested exception is java.lang.NullPointerException
解决:
如果项目中未引入 spring-boot-starter-actuator,则直接在 yml 文件中加入如下配置:
spring:
mvc:
pathmatch:
matching-strategy: ant-path-matcher 反之再添加如下配置:
@Bean
public WebMvcEndpointHandlerMapping webEndpointServletHandlerMapping(WebEndpointsSupplier webEndpointsSupplier, ServletEndpointsSupplier servletEndpointsSupplier, ControllerEndpointsSupplier controllerEndpointsSupplier, EndpointMediaTypes endpointMediaTypes, CorsEndpointProperties corsProperties, WebEndpointProperties webEndpointProperties, Environment environment) {
List<ExposableEndpoint<?>> allEndpoints = new ArrayList();
Collection<ExposableWebEndpoint> webEndpoints = webEndpointsSupplier.getEndpoints();
allEndpoints.addAll(webEndpoints);
allEndpoints.addAll(servletEndpointsSupplier.getEndpoints());
allEndpoints.addAll(controllerEndpointsSupplier.getEndpoints());
String basePath = webEndpointProperties.getBasePath();
EndpointMapping endpointMapping = new EndpointMapping(basePath);
boolean shouldRegisterLinksMapping = this.shouldRegisterLinksMapping(webEndpointProperties, environment, basePath);
return new WebMvcEndpointHandlerMapping(endpointMapping, webEndpoints, endpointMediaTypes, corsProperties.toCorsConfiguration(), new EndpointLinksResolver(allEndpoints, basePath), shouldRegisterLinksMapping, null);
}
private boolean shouldRegisterLinksMapping(WebEndpointProperties webEndpointProperties, Environment environment, String basePath) {
return webEndpointProperties.getDiscovery().isEnabled() && (StringUtils.hasText(basePath) || ManagementPortType.get(environment).equals(ManagementPortType.DIFFERENT));
}到此这篇关于SpringBoot2.6.x 与 Swagger3 兼容问题的文章就介绍到这了,更多相关SpringBoot2.6.x 与 Swagger3 兼容问题内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
使用mybatis报Invalid bound statement解决分析
这篇文章主要为大家介绍了使用mybatis报Invalid bound statement原因解决分析,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪2023-12-12
浅谈java String.split丢失结尾空字符串的问题
下面小编就为大家带来一篇浅谈java String.split丢失结尾空字符串的问题。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧2017-02-02


最新评论