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 upgrade the 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.

cpkarthic
  • 211
  • 1
  • 2
  • 3

4 Answers4

26

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.

Channa Jayamuni
  • 1,876
  • 1
  • 18
  • 29
  • 2
    Yes, that's it! If you compile on JDK 7 you can run on JRE 8 but you need 3.2.1.RELEASE version of Spring – Sergio Gabari Apr 16 '18 at 14:56
  • 1
    I have migrated to JDK8 while using spring 3.2.9 with target runtime 1.8. I haven't faced any issues so far. – arunken Aug 13 '20 at 05:59
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)

Ryba
  • 1,249
  • 10
  • 17
3

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.

Gaetan
  • 2,802
  • 2
  • 21
  • 26
-5

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.

kag0
  • 5,624
  • 7
  • 34
  • 67