Spring 3.2.x with Java 8

前端 未结 3 1808
长发绾君心
长发绾君心 2020-12-06 03:07

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

Along with 4.

相关标签:
3条回答
  • 2020-12-06 03:41

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

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

    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.

    0 讨论(0)
  • 2020-12-06 03:42

    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.

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

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

    0 讨论(0)
  • 2020-12-06 03:55

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

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

    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).

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

    0 讨论(0)
提交回复
热议问题