Java 8 Spring兼容性

时间:2015-08-28 19:56:10

标签: spring java-8

我目前正在将我的应用程序从Java 7迁移到Java 8,目前我正在运行Spring 3.1.6 jar。 这是否与Java 8兼容或者我需要升级Spring jar?

据我所知,Spring 4x版本对Java 8有自然支持,但这对时间至关重要,我正在努力改变尽可能少的罐子。

4 个答案:

答案 0 :(得分:17)

基本上Spring 3.x版本仅支持Java-7。如果您要迁移到Java-8,则应使用Spring 4.x版本。

  

然而,一些春季发行说明说Spring Framework 3.2.x   将支持在JDK 8运行时对已编译的应用程序进行部署   反对JDK 7(使用-target 1.7)或更早版本。请注意,它不会   支持JDK 8的字节码格式(-target 1.8,lambdas需要);   请为此目的升级到Spring Framework 4.0

关注源文章的__P链接。

答案 1 :(得分:3)

No it is not compatible. I've run into the same issue and while many will say that Java 8 is completely backwards compatible with older versions of java, this turns out not to be true.

This has a very good explaination of the exact problem I ran into java 7 targeted code with java 8.

https://gist.github.com/AlainODea/1375759b8720a3f9f094

Because the API of ConcurrentHashMap has changed between the 2 java releases, spring breaks on startup and you end up with

SEVERE: Context initialization failed
java.lang.NoSuchMethodError: java.util.concurrent.ConcurrentHashMap.keySet()Ljava/util/concurrent/ConcurrentHashMap$KeySetView;
    at org.apache.catalina.core.ApplicationContext.getInitParameterNames(ApplicationContext.java:368)
    at org.apache.catalina.core.ApplicationContextFacade.getInitParameterNames(ApplicationContextFacade.java:367)
    at org.springframework.web.context.support.WebApplicationContextUtils.registerEnvironmentBeans(WebApplicationContextUtils.java:201)
    at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.postProcessBeanFactory(AbstractRefreshableWebApplicationContext.java:163)

I had no choice to but upgrade to Spring 4.x (not sure if 3.2 or above would have worked as I jumped straight to 4.x)

答案 2 :(得分:1)

如果某些库(或JRE本身)是JDK 8并且启用了spring的组件扫描功能(并扫描这些libs / jdk类),那么最小的spring版本是3.2.10-RELEASE。

原因是在春季升级了ASM(Spring用于扫描编译类并检测注释,实现接口等的库)。

有关详细信息,请参阅SPR-11979SPR-11656

答案 3 :(得分:-5)

Java 8和jvm 8完全向后兼容所有旧版本的java。 Java采取了艰难的步骤来确保新版本不会破坏旧代码。您为java 7编写的任何代码都可以使用java 8编译,并且您为java 7编译的任何代码都可以在jvm 8上运行。