springboot 1 升级到 springboot2 问题记录

因公司要求,springboot的版本需要在2以上,刚开始以为并不是很麻烦,只需要升级jar包版本,但是后来发现事情并没有那么简单,以下是我升级springboot 版本时遇到的问题,有什么不对希望大家多指正。

一: ribbon,feign,hystrix jar包导入问题

        升级到springboot 2 这些包导入时pom文件需要修改:

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
</dependency>

ps:升级后 @EnableFeignClients等相关注解所在位置会发生变化(org.springframework.cloud.openfeign

),需要重新import。

二 Handler processing failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.core.KeyFactory

这个问题是自己有点懵了,刚开始我从抛出异常的地方一直进去发现没什么不对的,该有的jar都有,然后就开始怀疑idea,maven。。。。。后来发现在springboot1的时候是有导入cglib-nodep这个jar包,到springboot2 的时候就没了,后来手工加入到pom文件当中:版本大家根据自己springboot 适配,不适配真的可能会出莫名其妙的问题

<dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.2.2</version>
</dependency>
<dependency>
    <groupId>asm</groupId>
    <artifactId>asm</artifactId>
    <version>3.3.1</version>
</dependency>

三 后台返回字符串为时间戳 Long 类型而非 String 类型

       这个问题找了挺久的,后来发现有一个拦截器里面配置了这些,但是这个拦截器貌似过时了,找了相关springboot的资料这个类会覆盖 springboot中默认的一些配置:

解决:先使用springboot2中 推荐的 WebMvcConfigurationSupport 类 替换过时的 WebMvcConfigurerAdapter 类 然后增加相关日期格式化:

四   启动时:Factory method 'methodValidationPostProcessor' threw exception; nested exception is java.lang.StackOverflowError

异常如下:

pplication run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'methodValidationPostProcessor' defined in class path resource [org/springframework/boot/autoconfigure/validation/ValidationAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.validation.beanvalidation.MethodValidationPostProcessor]: Factory method 'methodValidationPostProcessor' threw exception; nested exception is java.lang.StackOverflowError
    at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:627)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:607)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1305)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1144)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515)
    at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320)

这个异常也找了蛮久了,最后其实只要升级下:jasypt-spring-boot-starter 就可以了,以后升级一定要全套升级~~

总结:升级一定要做全套!

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值