【SpringBoot1.5.x升级到SpringBoot2.2.13记录】

目录

为什么升级到2.x

SpringBoot1.x和SpringBoot2.x的一些区别

RelaxedPropertyResolver不可用

groovy异常

log4j-slf4j-impl cannot be present with log4j-to-slf4

overriding is disabled

其他相关版本升级参考


为什么升级到2.x

1.SpringBoot 1.X 官方已不再进行维护;

2.SpringBoot 1.X 下许多新发现的SpringBoot和SpringFramework的漏洞无法再进行升级处理,安全扫描无法通过;

3.SpringBoot 2.X 下的应用启动速度会比SpringBoot1提升10到20秒时间,整体性能上也更优。

首先我们了解一下Springboot1.x和Springboot2.x有哪些区别,这样升级的时候也能避免一些坑

SpringBoot1.x和SpringBoot2.x的一些区别

  1. SpringBoot 2基于Spring5和JDK8,而Spring 1x则用的是降低版本,应用服务必须支持JDK8
  2. MVC部分,有些定制类改动了,比如WebMvcConfiguer,由抽象类改为接口,这是因为JDK8对接口有新的支持形式;统一错误处理,基类AbstarctErrorController也改动非常大。业务代码中如有对MVC的拓展需要改为使用springboot 2 的方式
  3. SpringBoot2默认不允许覆盖bean操作,如果要覆盖需要显示配置支持
  4. SpringBoot2废弃外部化配置RelaxedPropertyResolver,可用Binder配合env进行绑定获取
  5. JPA中,findById 返回了一个Optional对象,改动较大,会直接影响所有业务代码
  6. Acutator 默认情况,不再启用所有监控,另外编写自己监控信息,完全需要重写,HealthIndicator,EndPoint 变化很大
  7. ……其他的后面再补充

下面记录一下我升级过程中遇到的问题和解决方案

RelaxedPropertyResolver不可用

具体报错是这样的

[main]org.springframework.boot.SpringApplication[826]: Application run failed org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'avoidRepeatableCommitAspect': Unsatisfied dependency expressed through field 'cacheConfig'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheConfig' defined in class path resource

[/cache/config/AutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [cache.config.CacheConfig]: Factory method 'cacheConfig' threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/bind/RelaxedPropertyResolver

原因:源于Environment 关注自动化,org.springframework.boot.bind 包将不再可用,现被 new relaxed binding infrastructure 替换。特别是,RelaxedDataBinder 相关的应用方式被替换为新的绑定API。

怎么解决呢?通过Binder以及相关绑定获取environment中的配置,具体方案往下看

通过Binder以及相关绑定获取environment中的配置

private static final Bindable<Map<String, Object>> STRING_REGISTRATION_MAP =
 Bindable.mapOf(String.class, Object.class);

groovy异常

报错gmavenplus:gmavenplus-plugin:1.6:compile failed.          Unable to determine Groovy version. Is Groovy declared as a dependency?

原因: groovy-all在springboot2中去掉了需要手动引入

解决:手动引入groovy jar即可

log4j-slf4j-impl cannot be present with log4j-to-slf4

原因:log4j-slf4j-impl 主要是 log4j 对 slf4j 接口的实现,而 log4j-to-slf4j 则是 slf4j 对 log4j 接口的适配,不能都有

解决:当前项目查找删除spring-boot-starter-test即可

overriding is disabled

The bean 'dynamicDataSourceAspect', defined in

DbAutoConfiguration, could not be registered. A bean with that name has already been defined in class path resource [xxx/ibatis/config/SpringConfigLoader.class] and overriding is disabled.

原因:springboot2新增加的配置,springboot不允许默认覆盖bean操作。如果要覆盖需要显式的配置支持解决

解决:properties增加配置spring.main.allow-bean-definition-overriding=true

其他相关版本升级参考

依赖    

升级前版本    

升级后版本    

备注

spring 

4.3.29    

5.2.20

spring-jdbc    

4.3.29    

5.2.20

otp-common-biz-unanimous去掉 spring-jdbc 指定版本号 4.3.29.RELEASE

commons-codec    

1.10    

1.14

bcpkix-jdk15on    

1.60    

1.64

druid    

1.1.20    

1.2.8

使用框架提供的druid版本

spock    

1.3-groovy-2.4

2.2-M1-groovy-3.0

groovy-all

2.4.15

3.0.9

byte-buddy

1.9.3

1.11.22

objenesis

2.6

3.2

hamcrest-core

1.3

2.2

        

好了,可能不是很全,但是已经完整的升上来了,厉害了吧

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我是小酒

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值