springboot读取bootstrap配置及knife4j版本兼容性问题

    因某些特殊原因,需要使用springboot项目读取bootstrap.yml中配置,然而添加bootstrap依赖包后,又引发了springboot、springcloud与knife4j版本匹配的问题=_=|| 这真是一个环。。。
    写篇文章,来记录下连环坑的‘快乐’心路历程~

项目框架说明

项目背景说明:
SpringBoot 2.2.5.RELEASE
knife4j 3.0.3

连环坑

  • 引入bootstrap启动前配置后,启动失败
  • 按照错误升级springboot版本至2.6.6后,启动失败
  • knife4j与springboot版本不兼容,需降springboot版本
  • 尝试三者的版本匹配

问题一:springboot项目无法读取bootstrap.yml配置

参考文献:springboot项目启动报错无法识别bootstrap.yml配置问题

出现此问题的原因:SpringBoot项目,只会识别application. *配置文件,并不会自动识别bootstrap.yml
解决方案:在pom.xml中添加了bootstrap启动器依赖

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-bootstrap</artifactId>
    <version>3.1.1</version>
</dependency>

问题二:启动报错,springboot与springcloud版本不匹配

错误如下:

Spring Boot [2.2.5.RELEASE] is not compatible with this Spring Cloud release train

Action:

Consider applying the following actions:

- Change Spring Boot version to one of the following versions [2.6.x, 2.7.x] .

没办法,按照错误升级springboot版本吧(初步尝试2.6.6)

问题三:启动报错Failed to start bean ‘documentationPluginsBootstrapper’

错误如下:

org.springframework.context.ApplicationContextException: Failed to start bean 'documentationPluginsBootstrapper'

在网上查找了下相关问题,参考文献:org.springframework.context.ApplicationContextException的解决办法,发现是knife4j(swagger)与springboot版本不匹配,得降低springboot版本!!!

另一种解决方案:修改springmvc的路径匹配策略 - 待验证

因为Springfox使用的路径匹配是基于AntPathMatcher的,而Spring Boot 2.6.X使用的是PathPatternMatcher。
#解决:在application.properties里配置
spring.mvc.pathmatch.matching-strategy=ANT_PATH_MATCHER

版本匹配

springboot与bootstrap(springcloud)

bootstrap(springcloud)版本 springboot版本
3.0.1及3.0.0 [2.3.x, 2.4.x]
3.0.3 [2.4.x, 2.5.x]
3.1.1 [2.6.x, 2.7.x]

最终版本方案

SpringBoot 2.4.13 + SpringCloud 3.0.1 + knife4j 3.0.3 终于可以了!!!!

扫描二维码关注公众号,回复: 15013145 查看本文章

后记:不要轻易升级版本

血的教训啊,想着knife4j升级一个大版本看下新特性,结果引发了一系列问题~
ps:自己对于框架的知识还是不够清楚啊,得努力学习喽~

猜你喜欢

转载自blog.csdn.net/huhui806/article/details/125387443