SpringBoot2.6.x 与 Swagger3 兼容问题及解决方法
作者:大大怪将军~~~~
文章介绍了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 兼容问题内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!