Spring Framework版本升级
作者:mmseoamin日期:2023-12-25

升级Spring Framework 版本

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

​ 对于springboot项目,查看springboot版本和他依赖的Spring Framework的对应关系(从这个网址查询,修改地址中的2.6.6为你要查询的版本号)

springboot版本依赖springframework版本发布时间
1.0.x
1.0.0.RELEASE4.0.3.RELEASE2014.04
1.0.1.RELEASE4.0.3.RELEASE2014.04
1.0.2.RELEASE4.0.3.RELEASE2014.04
1.1.x
1.1.0.RELEASE4.0.5.RELEASE2014.06
1.1.1.RELEASE4.0.5.RELEASE2014.06
1.1.2.RELEASE4.0.5.RELEASE2014.06
1.1.3.RELEASE4.0.5.RELEASE2014.06
1.1.4.RELEASE4.0.6.RELEASE2014.07
1.1.5.RELEASE4.0.6.RELEASE2014.08
1.1.6.RELEASE4.0.6.RELEASE2014.09
1.1.7.RELEASE4.0.7.RELEASE2014.09
1.1.8.RELEASE4.0.7.RELEASE2014.10
1.1.9.RELEASE4.0.8.RELEASE2014.11
1.1.10.RELEASE4.0.8.RELEASE2014.12
1.1.11.RELEASE4.0.9.RELEASE2015.02
1.1.12.RELEASE4.0.9.RELEASE2015.03
1.2.x
1.2.0.RELEASE4.1.3.RELEASE2014.12
1.2.1.RELEASE4.1.4.RELEASE2015.01
1.2.2.RELEASE4.1.5.RELEASE2015.02
1.2.3.RELEASE4.1.6.RELEASE2015.03
1.2.4.RELEASE4.1.6.RELEASE2015.06
1.2.5.RELEASE4.1.7.RELEASE2015.07
1.2.6.RELEASE4.1.8.RELEASE2015.09
1.2.7.RELEASE4.1.3.RELEASE2015.10
1.2.8.RELEASE4.1.9.RELEASE2015.12
1.3.x
1.3.0.RELEASE4.2.3.RELEASE2015.11
1.3.1.RELEASE4.2.4.RELEASE2015.12
1.3.2.RELEASE4.2.4.RELEASE2016.01
1.3.3.RELEASE4.2.5.RELEASE2016.02
1.3.4.RELEASE4.2.6.RELEASE2016.05
1.3.5.RELEASE4.2.6.RELEASE2016.05
1.3.6.RELEASE4.2.7.RELEASE2016.06
1.3.7.RELEASE4.2.7.RELEASE2016.06
1.3.8.RELEASE4.2.8.RELEASE2016.09
1.4.x
1.4.0.RELEASE4.3.2.RELEASE2016.07
1.4.1.RELEASE4.3.3.RELEASE2016.09
1.4.2.RELEASE4.3.4.RELEASE2016.11
1.4.3.RELEASE4.3.5.RELEASE2016.12
1.4.4.RELEASE4.3.6.RELEASE2017.01
1.4.5.RELEASE4.3.7.RELEASE2017.03
1.4.6.RELEASE4.3.8.RELEASE2017.04
1.4.7.RELEASE4.3.9.RELEASE2017.06
1.5.x
1.5.0.RELEASE4.3.6.RELEASE2017.01
1.5.1.RELEASE4.3.6.RELEASE2017.01
1.5.2.RELEASE4.3.7.RELEASE2017.03
1.5.3.RELEASE4.3.8.RELEASE2017.04
1.5.4.RELEASE4.3.9.RELEASE2017.06
1.5.5.RELEASE4.3.10.RELEASE2017.07
1.5.6.RELEASE4.3.10.RELEASE2017.07
1.5.7.RELEASE4.3.11.RELEASE2017.09
1.5.8.RELEASE4.3.12.RELEASE2017.10
1.5.9.RELEASE4.3.13.RELEASE2017.11
1.5.10.RELEASE4.3.14.RELEASE2018.01
1.5.11.RELEASE4.3.15.RELEASE2018.04
1.5.12.RELEASE4.3.16.RELEASE2018.04
1.5.13.RELEASE4.3.17.RELEASE2018.05
1.5.14.RELEASE4.3.18.RELEASE2018.06
1.5.15.RELEASE4.3.18.RELEASE2018.07
1.5.16.RELEASE4.3.19.RELEASE2018.09
1.5.17.RELEASE4.3.20.RELEASE2018.10
1.5.18.RELEASE4.3.21.RELEASE2018.11
1.5.19.RELEASE4.3.22.RELEASE2019.01
1.5.20.RELEASE4.3.23.RELEASE2019.04
1.5.21.RELEASE4.3.24.RELEASE2019.05
1.5.22.RELEASE4.3.25.RELEASE2019.08
2.0.x
2.0.0.RELEASE5.0.4.RELEASE2018.03
2.0.1.RELEASE5.0.5.RELEASE2018.04
2.0.2.RELEASE5.0.6.RELEASE2018.05
2.0.3.RELEASE5.0.7.RELEASE2018.06
2.0.4.RELEASE5.0.8.RELEASE2018.07
2.0.5.RELEASE5.0.9.RELEASE2018.09
2.0.6.RELEASE5.0.10.RELEASE2018.10
2.0.7.RELEASE5.0.11.RELEASE2018.11
2.0.8.RELEASE5.0.12.RELEASE2019.01
2.0.9.RELEASE5.0.13.RELEASE2019.04
2.1.x
2.1.0.RELEASE5.1.2.RELEASE2018.10
2.1.1.RELEASE5.1.3.RELEASE2018.11
2.1.2.RELEASE5.1.4.RELEASE2019.01
2.1.3.RELEASE5.1.5.RELEASE2019.02
2.1.4.RELEASE5.1.6.RELEASE2019.04
2.1.5.RELEASE5.1.7.RELEASE2019.05
2.1.6.RELEASE5.1.8.RELEASE2019.06
2.1.7.RELEASE5.1.9.RELEASE2019.08
2.1.8.RELEASE5.1.9.RELEASE2019.09
2.1.9.RELEASE5.1.10.RELEASE2019.10
2.1.10.RELEASE5.1.11.RELEASE2019.11
2.1.11.RELEASE5.1.12.RELEASE2019.12
2.1.12.RELEASE5.1.13.RELEASE2020.01
2.1.13.RELEASE5.1.14.RELEASE2020.02
2.1.14.RELEASE5.1.15.RELEASE2020.05
2.1.15.RELEASE5.1.16.RELEASE2020.06
2.1.16.RELEASE5.1.17.RELEASE2020.07
2.1.17.RELEASE5.1.18.RELEASE2020.09
2.1.18.RELEASE5.1.19.RELEASE2020.10
2.2.x
2.2.0.RELEASE5.2.0.RELEASE2019.10
2.2.1.RELEASE5.2.1.RELEASE2019.11
2.2.2.RELEASE5.2.2.RELEASE2019.12
2.2.3.RELEASE5.2.3.RELEASE2020.01
2.2.4.RELEASE5.2.3.RELEASE2020.01
2.2.5.RELEASE5.2.4.RELEASE2020.02
2.2.6.RELEASE5.2.5.RELEASE2020.03
2.2.7.RELEASE5.2.6.RELEASE2020.05
2.2.8.RELEASE5.2.7.RELEASE2020.06
2.2.9.RELEASE5.2.8.RELEASE2020.07
2.2.10.RELEASE5.2.9.RELEASE2020.09
2.2.11.RELEASE5.2.10.RELEASE2020.10
2.2.12.RELEASE5.2.12.RELEASE2020.11
2.2.13.RELEASE5.2.12.RELEASE2021.01
2.3.x
2.3.0.RELEASE5.2.6.RELEASE2020.05
2.3.1.RELEASE5.2.7.RELEASE2020.06
2.3.2.RELEASE5.2.8.RELEASE2020.07
2.3.3.RELEASE5.2.8.RELEASE2020.08
2.3.4.RELEASE5.2.9.RELEASE2020.09
2.3.5.RELEASE5.2.10.RELEASE2020.10
2.3.6.RELEASE5.2.11.RELEASE2020.11
2.3.7.RELEASE5.2.12.RELEASE2020.12
2.3.8.RELEASE5.2.12.RELEASE2021.01
2.3.9.RELEASE5.2.13.RELEASE2021.02
2.3.10.RELEASE5.2.14.RELEASE2021.04
2.3.11.RELEASE5.2.15.RELEASE2021.05
2.3.12.RELEASE5.2.15.RELEASE2021.06
2.4.x
2.4.05.3.12020.11
2.4.15.3.22020.12
2.4.25.3.32021.01
2.4.35.3.42021.02
2.4.45.3.52021.03
2.4.55.3.62021.04
2.4.65.3.72021.05
2.4.75.3.82021.06
2.4.85.3.82021.06
2.4.95.3.92021.07
2.4.105.3.92021.08
2.4.115.3.102021.09
2.4.125.3.122021.10
2.4.135.3.132021.11
2.5.x
2.5.05.3.72021.05
2.5.15.3.82021.06
2.5.25.3.82021.06
2.5.35.3.92021.07
2.5.45.3.92021.08
2.5.55.3.102021.09
2.5.65.3.122021.10
2.5.75.3.132021.11
2.5.85.3.142021.12
2.6.x
2.6.05.3.132021.11
2.6.15.3.132021.11
2.6.25.3.142021.12
2.6.35.3.152022.01
2.6.45.3.162022.02
2.6.55.3.172022.03
2.6.65.3.182022.03
2.6.75.3.192022.04
2.6.85.3.202022.05
2.6.95.3.212022.06
2.7.x
2.7.05.3.202022.05
2.7.15.3.212022.06

通过上述表格的对应关系,springboot2.6.6版本默认依赖的spring framework版本为5.3.18,所以可以通过升级springboot版本来升级spring framework的版本。

方法一:

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

org.springframework.boot spring-boot-starter-parent 2.6.6

方法二:

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

2.6.6

遇到的问题:

  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.(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.(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.(MappingJackson2HttpMessageConverter.java:59) at org.springframework.http.converter.support.AllEncompassingFormHttpMessageConverter.(AllEncompassingFormHttpMessageConverter.java:91) at org.springframework.web.filter.FormContentFilter.(FormContentFilter.java:61) at org.springframework.boot.web.servlet.filter.OrderedFormContentFilter.(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.(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:

org.springframework spring-core 5.3.18 org.springframework spring-context 5.3.18 org.springframework spring-jdbc 5.3.18

3.总结
  1. springboot项目可通过升级springboot版本来升级默认依赖的spring framework版本
  2. maven项目可直接在标签中直接指定spring framework相关依赖的版本