Search code examples
javaspring-bootspring-boot-maven-plugin

How does SpringBoot 2.7.x support multi-version JDK


SpringBoot 2.7.x is known to be developed using JDK 1.8, but when we introduce the Spring Boot 2.7.x dependency, we can develop and run on JDK 1.8, JDK 11, and JDK 17.

I want to figure out how Spring Boot support multi-version JDK running, and how SpringBoot handle deprecated API or dependency(e.g if we use JDK 11, rt.jar will not inclued in classpath, how SpringBoot reslove this problem?). is SpringBoot avoid to use deprecated API or is there a way to choose an API based on the JDK version.

In my opinion, if SpringBoot 2.7.x use API which is removed in JDK 8+, users who use JDK 11 or JDK 17 will encounter ClassNotFoundException when start the application. Could anyone tell me how SpingBoot resolve this problem? Or are they just using APIs that can be used in JDK 1.8, JDK 11, and JDK 17.

Thanks in advance!


Solution

  • Generally speaking, Java is very backwards compatible and APIs are rarely removed. This means that there are very few APIs that exist in Java 8 but don't exist in Java 17.

    Or are they just using APIs that can be used in JDK 1.8, JDK 11, and JDK 17.

    Thanks to the backwards compatibility described above, this is what Spring Boot is able to do at the moment with no real disadvantages.

    This will change a little with Java 21. Spring Boot 3.2 will add support for virtual threads which are new, (other than earlier preview releases) in Java 21. Spring Framework's virtual thread support is implemented using a multi-release jar with Java 21-specific code interacting with the JDK's virtual threads APIs. This will allow Spring Framework 6.1 and Spring Boot 3.2 to support virtual threads while also continuing to support earlier JDKs. Spring Boot will enable Spring Framework's virtual thread support on Java 21 and later using its @ConditionalOnJava support.