1. 程式人生 > 其它 >SpringBoot整合Swagger報錯:Failed to start bean 'documentationPluginsBootstrapper';

SpringBoot整合Swagger報錯:Failed to start bean 'documentationPluginsBootstrapper';

SpringBoot整合Swagger報錯,Failed to start bean 'documentationPluginsBootstrapper';SpringBoot版本過高導致路徑不匹配

SpringBoot整合Swagger報錯

報錯提示:

Failed to start bean 'documentationPluginsBootstrapper';

如下圖:

報錯原因:

由於Spring Boot 2.6.x 請求路徑與 Spring MVC 處理對映匹配的預設策略從AntPathMatcher更改為PathPatternParser。所以需要設定spring.mvc.pathmatch.matching-strategy為ant-path-matcher來改變它。

解決方法:

方案一(推薦):

修改SpringMVC路徑匹配規則,在配置檔案application.properties

檔案中新增以下程式碼

spring.mvc.pathmatch.matching-strategy=ant_path_matcher

若配置檔案為application.yml,則新增以下程式碼

spring:
  mvc:
    pathmatch:
      matching-strategy: ant_path_matcher

方案二:

將pom.xml依賴中的Spring Boot 版本號修改到2.6.0以下

Spring專案:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.5.6</version>
    <relativePath/> 
</parent>

Maven專案:

<!--spring-boot-web依賴-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
    <version>2.5.4</version>
</dependency>

處理結果:

專案就可以正常執行了