带有 Java 8 的 Spring 3.2.x

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30072135/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 16:24:10  来源:igfitidea点击:

Spring 3.2.x with Java 8

javaspringjava-8version

提问by Thusitha Thilina Dayaratne

We are currently using spring 3.2.9. We are thinking of upgrading that to a newer version. When I checked the documentation it says that

我们目前使用的是 spring 3.2.9。我们正在考虑将其升级到较新的版本。当我检查文档时,它说

Along with 4.0 M1, we've released Spring Framework 3.2.3, containing fixes for recently reported issues but also coming with OpenJDK 8 runtime support. Spring Framework 3.2.x will support deployment on JDK 8 runtimes for applications compiled against JDK 7 (with -target 1.7) or earlier.

除了 4.0 M1,我们还发布了 Spring Framework 3.2.3,其中包含针对最近报告的问题的修复程序,但还提供了 OpenJDK 8 运行时支持。Spring Framework 3.2.x 将支持在 JDK 8 运行时上部署针对 JDK 7(使用 -target 1.7)或更早版本编译的应用程序。

Does that imply that I can't compile on Java 8?
Should I use spring version 4.0.x if I wanna compile with Java 8?

这是否意味着我无法在 Java 8 上编译?
如果我想用 Java 8 编译,我应该使用 spring 版本 4.0.x 吗?

采纳答案by Brian Clozel

There is a best effort support of JDK8 in the 3.2.x line, as of 3.2.9+.

从 3.2.9+ 开始,在 3.2.x 行中有对 JDK8 的尽力支持。

See SPR-11656for initial support in 3.2.9 and SPR-11979for bytecode support improvements in 3.2.10. Please note the support limitations explained in the comments.

请参阅SPR- 11656以了解3.2.9 中的初始支持和SPR-11979以了解 3.2.10 中的字节码支持改进。请注意评论中解释的支持限制。

For comprehensive support of JDK8, please upgrade to Spring 4.x - there's a dedicated wiki page explaining the upgrade path, and the Spring team made great efforts to make that upgrade experience really easy.

为了全面支持 JDK8,请升级到 Spring 4.x - 有一个专门的 wiki 页面解释了升级路径,并且 Spring 团队努力使升级体验变得非常简单。

回答by mhlz

Versions of the Spring Framework that are older than 4.0M1 do not work with classes that are compiled for Java 8.

早于 4.0M1 的 Spring Framework 版本不适用于为 Java 8 编译的类。

Spring tries to Proxy these classes by reading class files, which won't work if they're "too new". If your @Serviceclasses are compiled with Java 8 as the target, Spring will fail to load the classes on startup.

Spring 尝试通过读取类文件来代理这些类,如果它们“太新”就行不通。如果您的@Service类是以 Java 8 作为目标编译的,Spring 将无法在启动时加载这些类。

This means that you will have to upgrade to Spring 4.x.x, if you want to target Java 8 (and use lambdas, default implementations and so on).

这意味着如果您想要面向 Java 8(并使用 lambdas、默认实现等),您将必须升级到 Spring 4.xx。

I encountered this problem myself a few months ago with a project that uses Spring 3.x.x.

几个月前我自己在一个使用 Spring 3.xx 的项目中遇到了这个问题

回答by BiAiB

As per my observations, you can actually use spring 3 with code compiled in Java 8, as long as you do not use new java8 syntax in there(like lambdas) in the paths scanned.

根据我的观察,您实际上可以将 spring 3 与在 Java 8 中编译的代码一起使用,只要您不在扫描的路径中使用新的 java8 语法(如 lambdas)。

So, you can use new APIs (streams ...), but not new syntax (lambdas...).

因此,您可以使用新的 API(流...),但不能使用新的语法(lambdas...)。

When I tried, I ended up with startup errors like org.springframework.beans.factory.BeanDefinitionStoreException: Failed to read candidate component class

当我尝试时,我最终遇到了诸如org.springframework.beans.factory.BeanDefinitionStoreException: Failed to readCandidate component class 之类的启动错误