spring boot版本升级遇到的一些问题

背景:由于项目需求,需要将nacos 1.4.6版本升级到2.x版本,由此引发的springboot、springcloud、springcloud Alibaba一系列版本变更。

旧版本分别为:

Spring Boot 2.3.5.RELEASE

Spring Cloud Hoxton.SR9

Spring Cloud Alibaba 2.2.6.RELEASE

一、版本选择

1、springboot2.x.x及以下使用jdk11、jdk8都可以,springboot3.x.x最低要求jdk17。首先确定springboot版本需要支持jdk8,即需要springboot2.x.x。

2、根据项目需求,选择合适的版本。

参考:Git版本说明网址:(组件版本以及依赖关系)

例:要考虑支持nacos2.x,所以红框内是可选。

Spring Cloud Alibaba 需要在2.2.8.RELEASE及以上,红框内是可选。

最终确定选择用*标记的最新版本。

Spring Boot 2.6.13

Spring Cloud 2021.0.5

Spring Cloud Alibaba 2021.0.5.0

nacos 2.2.0

二、奇奇怪怪的坑

1、循环依赖

springboot升级为2.6.13后项目启动报错:

Action:

Relying upon circular references is discouraged and they are prohibited by default. Update your application to remove the dependency cycle between beans. As a last resort, it may be possible to break the cycle automatically by setting spring.main.allow-circular-references to true.

出现的bug大概意思是:不鼓励依赖循环引用,默认情况下是禁止的。更新您的应用程序以删除 bean 之间的依赖循环。作为最后的手段,可以通过将 spring.main.allow-circular-references 设置为 true 来自动中断循环。

没有特殊处理代码,最后选择了修改yml配置文件,按照提示添加如下配置

yaml 复制代码
spring:
  main:
    allow-circular-references:true

2、quartz数据源配置

springboot升级为2.6.13后项目启动报错:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'quartzScheduler' defined in class path resource [org/springframework/boot/autoconfigure/quartz/QuartzAutoConfiguration.class]: Invocation of init method failed; nested exception is org.quartz.SchedulerConfigException: DataSource name not set.

报错原因:

spring-boot-starter-quartz 2.5.6 之前使用org.quartz.impl.jdbcjobstore.JobStoreTX定义quartz的默认数据源支持,quartz.properties如下

bash 复制代码
org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX

2.5.6的版本后将不再支持以上方式进行配置默认数据源,需改为如下配置

bash 复制代码
org.quartz.jobStore.class=org.springframework.scheduling.quartz.LocalDataSourceJobStore

3、跨域问题

项目启动成功,前端访问报错:

去网上查了原因后,是升级后spring的CorsFilter类针对CorsConfiguration新增了校验,最后修改方案是继续使用CorsFilter,使用官方推荐的allowedOriginPatterns即可,如下

java 复制代码
// corsConfiguration.addAllowedOrigin("*");
corsConfiguration.addAllowedOriginPattern("*");

想看详细涉及源码的可以看这篇:记一次spring boot升级跨域问题的坑

4、版本依赖排除

升级后sentinel相关提示找不到依赖错误,cant reslove fastjson:1.2.83_noneautotype

排除当前使用的版本,引用maven仓库中有的版本

5、Druid的一个bug

抛出异常:maxEvictableIdleTimeMillis must be grater than minEvictableIdleTimeMillis。

Druid-1.1.10 升级为 Druid-1.1.22

具体详细可参考这篇文章:Druid的一个Bug

相关推荐
铁皮哥8 小时前
【后端开发】@Resource 和 @Autowired 到底有什么区别?为什么现在更推荐构造方法注入?
java·ide·spring boot·tomcat·log4j·idea·intellij idea
众创岛8 小时前
web自动化中的日志模块
java·前端·自动化
EthanYuan8 小时前
🦴不是MCP害了我,是这个阻塞害了我啊
后端
焦糖玛奇朵婷8 小时前
终于搞清楚了,扭蛋机小程序这么厉害❗
java·服务器·前端·程序人生·小程序
用户298698530148 小时前
Java 文档处理:在 Word 中插入分页符与分节符
java·后端
fliter8 小时前
分布式聚合查询的工程内幕:Cloudflare R2 SQL 如何实现 GROUP BY
后端
APIshop8 小时前
Java 调用阿里巴巴商品详情接口实战指南:完整流程与代码实现
java·开发语言
RuoyiOffice8 小时前
低代码平台荣耀不再:AI 浪潮下,企业系统为什么重新回到原生代码
人工智能·spring boot·低代码·ai·vue·uniapp·ruoyioffice
贫民窟的勇敢爷们8 小时前
Spring Security OAuth2.0 技术详解:分布式系统安全认证的标准方案
java·安全·spring
无限进步_8 小时前
【C++】红黑树完全解析:从概念到插入与平衡维护
java·c语言·开发语言·数据结构·c++·后端·算法