Java 8 Spring compatibility

前端 未结 4 972
挽巷
挽巷 2020-11-29 11:21

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 upgr

相关标签:
4条回答
  • 2020-11-29 11:33

    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.

    However some spring release notes says that the Spring Framework 3.2.x will support deployment on JDK 8 runtimes for applications compiled against JDK 7 (with -target 1.7) or earlier. Note that it won’t support JDK 8’s bytecode format (-target 1.8, as needed for lambdas); please upgrade to Spring Framework 4.0 for that purpose.

    Follow this link to the source article.

    0 讨论(0)
  • 2020-11-29 11:42

    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.

    The reason is the upgrade of ASM (the library that spring uses to scan compiled classes and detect annotations, implemented interfaces, etc.) in spring.

    See SPR-11979 and SPR-11656 for details.

    0 讨论(0)
  • 2020-11-29 11:46

    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.

    0 讨论(0)
  • 2020-11-29 11:47

    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)

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