Java 8 Spring 兼容性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/32278878/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Java 8 Spring compatibility
提问by cpkarthic
I am currently migrating my application from Java 7 to Java 8 and currently I am running the Spring 3.1.6 jar. Would this be compatible with Java 8 or I need to upgrade the Spring jar ?
我目前正在将我的应用程序从 Java 7 迁移到 Java 8,目前我正在运行 Spring 3.1.6 jar。这会与 Java 8 兼容还是我需要升级 Spring jar ?
I understand that the Spring 4x version has natural support for Java 8, but this is time critical and I am seeking to change as little jars as I can.
我知道 Spring 4x 版本自然支持 Java 8,但这是时间紧迫的,我正在寻求尽可能少地更改 jars。
回答by Channa Jayamuni
Basically Spring 3.x
versions supports up to Java-7
only. If you want to migrate to Java-8
you should use Spring 4.x
version.
基本上Spring 3.x
版本最多Java-7
只支持。如果你想迁移到Java-8
你应该使用Spring 4.x
版本。
However some spring release notes says that the
Spring Framework 3.2.x
will support deployment onJDK 8
runtimes for applications compiled againstJDK 7
(with -target 1.7) or earlier. Note that it won't supportJDK 8
's bytecode format (-target 1.8, as needed for lambdas); please upgrade toSpring Framework 4.0
for that purpose.
然而,一些 spring 发行说明表示,
Spring Framework 3.2.x
将支持在JDK 8
运行时部署针对JDK 7
(使用 -target 1.7)或更早版本编译的应用程序。请注意,它不支持JDK 8
的字节码格式(-target 1.8,根据 lambdas 的需要);请Spring Framework 4.0
为此目的升级到。
Follow thislink to the source article.
按照此链接转到源文章。
回答by Ryba
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.
不,它不兼容。我遇到了同样的问题,虽然很多人会说 Java 8 与旧版本的 Java 完全向后兼容,但事实证明并非如此。
This has a very good explaination of the exact problem I ran into java 7 targeted code with java 8.
这很好地解释了我在 java 8 中遇到 java 7 目标代码的确切问题。
https://gist.github.com/AlainODea/1375759b8720a3f9f094
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
因为 ConcurrentHashMap 的 API 在 2 个 java 版本之间发生了变化,启动时突然中断,你最终
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)
我别无选择,只能升级到 Spring 4.x(不确定 3.2 或更高版本是否可行,因为我直接跳到了 4.x)
回答by Gaetan
If some libraries (or the JRE itself) are JDK 8 and the component-scan feature of spring is enabled (and scans these libs/jdk classes), then the minimal spring version is 3.2.10-RELEASE.
如果某些库(或 JRE 本身)是 JDK 8 并且启用了 spring 的组件扫描功能(并扫描这些库/jdk 类),那么最小的 spring 版本是 3.2.10-RELEASE。
The reason is the upgrade of ASM (the library that spring uses to scan compiled classes and detect annotations, implemented interfaces, etc.) in spring.
原因是spring升级了ASM(spring用来扫描编译类和检测注解、实现接口等的库)。
回答by kag0
Java 8 and the jvm 8 is completely backwards compatible with all older versions of java. Java takes painstaking steps to ensure new releases do not break old code. Any code you wrote for java 7 can be compiled with java 8, and any code you compiled for java 7 can run on jvm 8.
Java 8 和 jvm 8 完全向后兼容所有旧版本的 Java。Java 采取艰苦的步骤来确保新版本不会破坏旧代码。您为 java 7 编写的任何代码都可以用 java 8 编译,您为 java 7 编译的任何代码都可以在 jvm 8 上运行。