SpringBoot2.6.x 與 Swagger3 兼容問題及解決方法
報錯:
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 兼容問題內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
SpringMVC實現(xiàn)獲取請求參數(shù)方法詳解
Spring MVC 是 Spring 提供的一個基于 MVC 設計模式的輕量級 Web 開發(fā)框架,本質上相當于 Servlet,Spring MVC 角色劃分清晰,分工明細,這篇文章主要介紹了SpringMVC實現(xiàn)獲取請求參數(shù)方法2022-09-09
Java連接Emqx實現(xiàn)訂閱發(fā)布消息的步驟記錄
這篇文章主要介紹了Java連接Emqx實現(xiàn)訂閱發(fā)布消息的步驟記錄,EMQX是大規(guī)模分布式MQTT消息服務器,可以高效可靠連接海量物聯(lián)網設備,實時處理分發(fā)消息與事件流數(shù)據,助力構建關鍵業(yè)務的物聯(lián)網與云應用,需要的朋友可以參考下2025-09-09
做java這么久了居然還不知道JSON的使用(一文帶你了解)
這篇文章主要介紹了做java這么久了居然還不知道JSON的使用(一文帶你了解),本文通過實例代碼給大家介紹的非常詳細,對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-07-07
SpringBoot結合Vue實現(xiàn)Python在線調試器
這篇文章主要為大家詳細介紹了SpringBoot如何結合Vue實現(xiàn)Python在線調試器,文中的示例代碼講解詳細,感興趣的小伙伴可以跟隨小編一起學習一下2026-01-01

