Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java 8 Spring compatibility

Tags:

spring

java-8

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.

like image 246
cpkarthic Avatar asked Aug 28 '15 19:08

cpkarthic


People also ask

Does Spring Boot work with Java 8?

Spring Boot 2.7. 5 requires Java 8 and is compatible up to and including Java 19.

Is Spring 5 compatible with older versions of Java?

Spring 5 supports Java EE 7 and also compatible with Java EE 8. So we can use Servlet 4.0, Bean Validation 2.0, JPA 2.2 in our applications. We can also use their older versions i.e. Servlet 3.1, Bean Validation 1.1, JPA 2.1. Spring 5 applications preferred server versions are Tomcat 8.5+, Jetty 9.4+ and WildFly 10+.

Is Java 8 backwards compatible?

Incompatibilities between Java SE 8 and Java SE 7. Java SE 8 is strongly compatible with previous versions of the Java platform. Almost all existing programs should run on Java SE 8 without modification.

Does Spring support Java 7?

By default, Spring Boot 1.4. 1. RELEASE requires Java 7 and Spring Framework 4.3.


2 Answers

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.

like image 172
Channa Jayamuni Avatar answered Sep 23 '22 18:09

Channa Jayamuni


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)

like image 22
Ryba Avatar answered Sep 23 '22 18:09

Ryba