The Problem:
The Spring Starter is showing ‘sourceCompatibility = ’17” for Spring Boot 3.0.5, even when Java 8 is selected. Is this expected behavior, or is something wrong?
The Solutions:
Solution 1: Spring Boot 3.0.x does not support Java 8
Spring Boot 3.0.x requires Java 17 or above, as specified in the official documentation. This is contrary to your expectation of using Java 8 with Spring Boot 3.0.x. When you selected Java 8 in Spring Starter, it set the sourceCompatibility
to 17, indicating that the code should be compatible with Java 17, not Java 8.
Solution 2:
Spring Boot 3 and above **requires Java 17**. It is mandatory to use Java 17 if you want to work with Spring Boot 3. The reason behind this is that Java 17 is a Long Term Support (LTS) release with extended support lifetime, which aligns with Spring Boot’s LTS policy. By requiring Java 17, Spring Boot ensures compatibility with a stable and widely supported Java version, providing a more reliable and long-lasting platform for running Spring applications.
Solution 3: Specify Java 8 for Spring Boot 2.X
Spring Boot 3.0.x requires Java 17 as a minimum version. To use Java 8, you need to use a Spring Boot 2.X version.
Specify the Spring Boot 2.X version in your project’s pom.xml
file, as shown in the below code:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.18</version>
<relativePath/>
</parent>
Q&A
Does Spring 3.0.x support Java 8?
No, Spring Boot 3 requires Java 17 or up.
Can I use Spring Boot 3 with Java 8?
No, Spring Boot 3 requires Java 17 or up.
What version of Spring Boot should I use with Java 8?
Spring Boot 2.7.18 is the last version that supports Java 8.
Video Explanation:
The following video, titled "Change Java version for a Spring Boot project (STS, NetBeans and ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
How to properly change Java version for a Spring Boot project in Spring Tool Suite, Apache NetBeans and IntelliJ IDEA - with Maven.
The following video, titled "Change Java version for a Spring Boot project (STS, NetBeans and ...", provides additional insights and in-depth exploration related to the topics discussed in this post.
How to properly change Java version for a Spring Boot project in Spring Tool Suite, Apache NetBeans and IntelliJ IDEA - with Maven.