因公司要求,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 就可以了,以后升级一定要全套升级~~
总结:升级一定要做全套!