【報錯】SpringBoot集成Swagger失敗:Failed to start bean 'documentationPluginsBootstrapper';


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>

處理結果:

項目就可以正常執行了


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM