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>
處理結果:
項目就可以正常執行了