0


Spring Framework版本升级

升级Spring Framework 版本

由于公司漏洞扫描后要求项目中Spring Framework版本不低于5.3.18,通过idea插件maven helper,查看所有项目中Spring Framework的版本,发现5个项目中的版本低于5.3.18,需要进行版本升级
1. springboot项目

​ 对于springboot项目,查看springboot版本和他依赖的Spring Framework的对应关系
springboot版本依赖springframework版本发布时间1.0.x1.0.0.RELEASE4.0.3.RELEASE2014.041.0.1.RELEASE4.0.3.RELEASE2014.041.0.2.RELEASE4.0.3.RELEASE2014.04–––1.1.x1.1.0.RELEASE4.0.5.RELEASE2014.061.1.1.RELEASE4.0.5.RELEASE2014.061.1.2.RELEASE4.0.5.RELEASE2014.061.1.3.RELEASE4.0.5.RELEASE2014.061.1.4.RELEASE4.0.6.RELEASE2014.071.1.5.RELEASE4.0.6.RELEASE2014.081.1.6.RELEASE4.0.6.RELEASE2014.091.1.7.RELEASE4.0.7.RELEASE2014.091.1.8.RELEASE4.0.7.RELEASE2014.101.1.9.RELEASE4.0.8.RELEASE2014.111.1.10.RELEASE4.0.8.RELEASE2014.121.1.11.RELEASE4.0.9.RELEASE2015.021.1.12.RELEASE4.0.9.RELEASE2015.03–––1.2.x1.2.0.RELEASE4.1.3.RELEASE2014.121.2.1.RELEASE4.1.4.RELEASE2015.011.2.2.RELEASE4.1.5.RELEASE2015.021.2.3.RELEASE4.1.6.RELEASE2015.031.2.4.RELEASE4.1.6.RELEASE2015.061.2.5.RELEASE4.1.7.RELEASE2015.071.2.6.RELEASE4.1.8.RELEASE2015.091.2.7.RELEASE4.1.3.RELEASE2015.101.2.8.RELEASE4.1.9.RELEASE2015.12–––1.3.x1.3.0.RELEASE4.2.3.RELEASE2015.111.3.1.RELEASE4.2.4.RELEASE2015.121.3.2.RELEASE4.2.4.RELEASE2016.011.3.3.RELEASE4.2.5.RELEASE2016.021.3.4.RELEASE4.2.6.RELEASE2016.051.3.5.RELEASE4.2.6.RELEASE2016.051.3.6.RELEASE4.2.7.RELEASE2016.061.3.7.RELEASE4.2.7.RELEASE2016.061.3.8.RELEASE4.2.8.RELEASE2016.09–––1.4.x1.4.0.RELEASE4.3.2.RELEASE2016.071.4.1.RELEASE4.3.3.RELEASE2016.091.4.2.RELEASE4.3.4.RELEASE2016.111.4.3.RELEASE4.3.5.RELEASE2016.121.4.4.RELEASE4.3.6.RELEASE2017.011.4.5.RELEASE4.3.7.RELEASE2017.031.4.6.RELEASE4.3.8.RELEASE2017.041.4.7.RELEASE4.3.9.RELEASE2017.06–––1.5.x1.5.0.RELEASE4.3.6.RELEASE2017.011.5.1.RELEASE4.3.6.RELEASE2017.011.5.2.RELEASE4.3.7.RELEASE2017.031.5.3.RELEASE4.3.8.RELEASE2017.041.5.4.RELEASE4.3.9.RELEASE2017.061.5.5.RELEASE4.3.10.RELEASE2017.071.5.6.RELEASE4.3.10.RELEASE2017.071.5.7.RELEASE4.3.11.RELEASE2017.091.5.8.RELEASE4.3.12.RELEASE2017.101.5.9.RELEASE4.3.13.RELEASE2017.111.5.10.RELEASE4.3.14.RELEASE2018.011.5.11.RELEASE4.3.15.RELEASE2018.041.5.12.RELEASE4.3.16.RELEASE2018.041.5.13.RELEASE4.3.17.RELEASE2018.051.5.14.RELEASE4.3.18.RELEASE2018.061.5.15.RELEASE4.3.18.RELEASE2018.071.5.16.RELEASE4.3.19.RELEASE2018.091.5.17.RELEASE4.3.20.RELEASE2018.101.5.18.RELEASE4.3.21.RELEASE2018.111.5.19.RELEASE4.3.22.RELEASE2019.011.5.20.RELEASE4.3.23.RELEASE2019.041.5.21.RELEASE4.3.24.RELEASE2019.051.5.22.RELEASE4.3.25.RELEASE2019.08–––2.0.x2.0.0.RELEASE5.0.4.RELEASE2018.032.0.1.RELEASE5.0.5.RELEASE2018.042.0.2.RELEASE5.0.6.RELEASE2018.052.0.3.RELEASE5.0.7.RELEASE2018.062.0.4.RELEASE5.0.8.RELEASE2018.072.0.5.RELEASE5.0.9.RELEASE2018.092.0.6.RELEASE5.0.10.RELEASE2018.102.0.7.RELEASE5.0.11.RELEASE2018.112.0.8.RELEASE5.0.12.RELEASE2019.012.0.9.RELEASE5.0.13.RELEASE2019.04–––2.1.x2.1.0.RELEASE5.1.2.RELEASE2018.102.1.1.RELEASE5.1.3.RELEASE2018.112.1.2.RELEASE5.1.4.RELEASE2019.012.1.3.RELEASE5.1.5.RELEASE2019.022.1.4.RELEASE5.1.6.RELEASE2019.042.1.5.RELEASE5.1.7.RELEASE2019.052.1.6.RELEASE5.1.8.RELEASE2019.062.1.7.RELEASE5.1.9.RELEASE2019.082.1.8.RELEASE5.1.9.RELEASE2019.092.1.9.RELEASE5.1.10.RELEASE2019.102.1.10.RELEASE5.1.11.RELEASE2019.112.1.11.RELEASE5.1.12.RELEASE2019.122.1.12.RELEASE5.1.13.RELEASE2020.012.1.13.RELEASE5.1.14.RELEASE2020.022.1.14.RELEASE5.1.15.RELEASE2020.052.1.15.RELEASE5.1.16.RELEASE2020.062.1.16.RELEASE5.1.17.RELEASE2020.072.1.17.RELEASE5.1.18.RELEASE2020.092.1.18.RELEASE5.1.19.RELEASE2020.10–––2.2.x2.2.0.RELEASE5.2.0.RELEASE2019.102.2.1.RELEASE5.2.1.RELEASE2019.112.2.2.RELEASE5.2.2.RELEASE2019.122.2.3.RELEASE5.2.3.RELEASE2020.012.2.4.RELEASE5.2.3.RELEASE2020.012.2.5.RELEASE5.2.4.RELEASE2020.022.2.6.RELEASE5.2.5.RELEASE2020.032.2.7.RELEASE5.2.6.RELEASE2020.052.2.8.RELEASE5.2.7.RELEASE2020.062.2.9.RELEASE5.2.8.RELEASE2020.072.2.10.RELEASE5.2.9.RELEASE2020.092.2.11.RELEASE5.2.10.RELEASE2020.102.2.12.RELEASE5.2.12.RELEASE2020.112.2.13.RELEASE5.2.12.RELEASE2021.01–––2.3.x2.3.0.RELEASE5.2.6.RELEASE2020.052.3.1.RELEASE5.2.7.RELEASE2020.062.3.2.RELEASE5.2.8.RELEASE2020.072.3.3.RELEASE5.2.8.RELEASE2020.082.3.4.RELEASE5.2.9.RELEASE2020.092.3.5.RELEASE5.2.10.RELEASE2020.102.3.6.RELEASE5.2.11.RELEASE2020.112.3.7.RELEASE5.2.12.RELEASE2020.122.3.8.RELEASE5.2.12.RELEASE2021.012.3.9.RELEASE5.2.13.RELEASE2021.022.3.10.RELEASE5.2.14.RELEASE2021.042.3.11.RELEASE5.2.15.RELEASE2021.052.3.12.RELEASE5.2.15.RELEASE2021.06–––2.4.x2.4.05.3.12020.112.4.15.3.22020.122.4.25.3.32021.012.4.35.3.42021.022.4.45.3.52021.032.4.55.3.62021.042.4.65.3.72021.052.4.75.3.82021.062.4.85.3.82021.062.4.95.3.92021.072.4.105.3.92021.082.4.115.3.102021.092.4.125.3.122021.102.4.135.3.132021.11–––2.5.x2.5.05.3.72021.052.5.15.3.82021.062.5.25.3.82021.062.5.35.3.92021.072.5.45.3.92021.082.5.55.3.102021.092.5.65.3.122021.102.5.75.3.132021.112.5.85.3.142021.12–––2.6.x2.6.05.3.132021.112.6.15.3.132021.112.6.25.3.142021.122.6.35.3.152022.012.6.45.3.162022.022.6.55.3.172022.032.6.65.3.182022.032.6.75.3.192022.042.6.85.3.202022.052.6.95.3.212022.06–––2.7.x2.7.05.3.202022.052.7.15.3.212022.06
通过上述表格的对应关系,springboot2.6.6版本默认依赖的spring framework版本为5.3.18,所以可以通过升级springboot版本来升级spring framework的版本。

方法一:

如果项目的parent中使用的是spring-boot-starter-parent,那么可以直接修改该版本号为5.6.6

<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>5.6.6</version> <relativePath/> <!-- lookup parent from repository --> </parent>

方法二:

如果parent中使用的是其他父依赖,那么可以通过在pom文件中添加spring-boot.version解决

<properties> <spring-boot.version>2.6.6</spring-boot.version> </properties>

遇到的问题:

  1. jackson-databind包版本不兼容:org.springframework.context.ApplicationContextException: Unable to start web server; nested exception is org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:163) at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:577) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:145) at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:740) at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:415) at org.springframework.boot.SpringApplication.run(SpringApplication.java:303) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312) at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301) at com.x5dtech.dwsim.Application.main(Application.java:21) Caused by: org.springframework.boot.web.server.WebServerException: Unable to start embedded Tomcat at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:142) at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.<init>(TomcatWebServer.java:104) at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getTomcatWebServer(TomcatServletWebServerFactory.java:478) at org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory.getWebServer(TomcatServletWebServerFactory.java:211) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.createWebServer(ServletWebServerApplicationContext.java:182) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.onRefresh(ServletWebServerApplicationContext.java:160) ... 8 common frames omitted Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'formContentFilter' defined in class path resource [org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:658) at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:486) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1352) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1195) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:335) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:333) at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:213) at org.springframework.boot.web.servlet.ServletContextInitializerBeans.getOrderedBeansOfType(ServletContextInitializerBeans.java:212) at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:175) at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAsRegistrationBean(ServletContextInitializerBeans.java:170) at org.springframework.boot.web.servlet.ServletContextInitializerBeans.addAdaptableBeans(ServletContextInitializerBeans.java:155) at org.springframework.boot.web.servlet.ServletContextInitializerBeans.<init>(ServletContextInitializerBeans.java:87) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.getServletContextInitializerBeans(ServletWebServerApplicationContext.java:260) at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.selfInitialize(ServletWebServerApplicationContext.java:234) at org.springframework.boot.web.embedded.tomcat.TomcatStarter.onStartup(TomcatStarter.java:53) at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5219) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) at org.apache.catalina.core.StandardHost.startInternal(StandardHost.java:835) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1396) at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1386) at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266) at java.util.concurrent.FutureTask.run(FutureTask.java) at org.apache.tomcat.util.threads.InlineExecutorService.execute(InlineExecutorService.java:75) at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:134) at org.apache.catalina.core.ContainerBase.startInternal(ContainerBase.java:919) at org.apache.catalina.core.StandardEngine.startInternal(StandardEngine.java:263) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardService.startInternal(StandardService.java:432) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.core.StandardServer.startInternal(StandardServer.java:927) at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:183) at org.apache.catalina.startup.Tomcat.start(Tomcat.java:486) at org.springframework.boot.web.embedded.tomcat.TomcatWebServer.initialize(TomcatWebServer.java:123) ... 13 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.web.servlet.filter.OrderedFormContentFilter]: Factory method 'formContentFilter' threw exception; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185) at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ... 56 common frames omitted Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.fasterxml.jackson.datatype.jsr310.JavaTimeModule]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:224) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:146) at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.registerWellKnownModulesIfAvailable(Jackson2ObjectMapperBuilder.java:832) at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.configure(Jackson2ObjectMapperBuilder.java:691) at org.springframework.http.converter.json.Jackson2ObjectMapperBuilder.build(Jackson2ObjectMapperBuilder.java:674) at org.springframework.http.converter.json.MappingJackson2HttpMessageConverter.<init>(MappingJackson2HttpMessageConverter.java:59) at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.<init>(AllEncompassingFormHttpMessageConverter.java:91) at org.springframework.web.filter.FormContentFilter.<init>(FormContentFilter.java:61) at org.springframework.boot.web.servlet.filter.OrderedFormContentFilter.<init>(OrderedFormContentFilter.java:29) at org.springframework.boot.autoconfigure.web.servlet.WebMvcAutoConfiguration.formContentFilter(WebMvcAutoConfiguration.java:179) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ... 57 common frames omitted Caused by: java.lang.NoClassDefFoundError: com/fasterxml/jackson/datatype/jsr310/ser/ZoneIdSerializer at com.fasterxml.jackson.datatype.jsr310.JavaTimeModule.<init>(JavaTimeModule.java:158) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211) ... 71 common frames omitted解决方式:通过在该网站中查找jackson-databind,找到推荐的版本,修改后解决 Spring Boot Reference Documentation
  2. pagehelper循环依赖:com.github.pagehelper.autoconfigure.PageHelperAutoConfiguration

​ 解决方式:由于springboot2.6禁止循环依赖导致,升级到1.4.1解决

2.maven项目

对于maven项目,我通过dependencyManagement标签直接升级了spring framework:

<dependencyManagement> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>5.3.18</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <version>5.3.18</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>5.3.18</version> </dependency> </dependencyManagement>
3.总结
  1. springboot项目可通过升级springboot版本来升级默认依赖的spring framework版本
  2. maven项目可直接在标签中直接指定spring framework相关依赖的版本
标签: spring spring boot java

本文转载自: https://blog.csdn.net/pany_2017/article/details/130163861
版权归原作者 pany_2017 所有, 如有侵权,请联系我们删除。

“Spring Framework版本升级”的评论:

还没有评论