关于springboot整合springcloud,springboot降版本报错等问题
在整合springcloud的过程中,需要springboot的版本要和springcloud的版本适配,不然会出现一系列的错误:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat’: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationPropertiesBean
这个错误是由于:
一开始springboot项目创建的时候是2.5.0版本,创建的同时选择了openfeign的依赖,创建完成会自动生成一系列springcloud的依赖:
由于特殊需要降级到了2.1.8.release版本:
同时改掉test测试类相关的import以及注解等,适应低版本springboot的测试类(这是更改以后的,这些都是低版本需要加上的):
运行springboot启动类,这个时候还是报错:
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘org.springframework.boot.autoconfigure.web.servlet.ServletWebServerFactoryConfiguration$EmbeddedTomcat’: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationPropertiesBean
找了一段时间,才想到现在springboot的版本和之前的springcloud的版本不匹配,于是改了springcloud的版本后,再重新启动就可以运行了。
springcloud的版本在springboot 2.5.0降版本之前:
springboot2.5.0降版本以后修改springcloud版本:
切记!!!:springboot版本 一定要与 springcloud 对应的版本匹配。具体版本号对应匹配文档,请自行去springcloud官网查看。