javaspring-boottomcatspring-tool-suitespring-boot-starter

Spring Tools 4 with Spring Boot, Java 11 and Tomcat 9


I come from Eclipse and I'm starting my first project in Spring (Boot). I'd like to use JDK 11.0.17 and Tomcat 9.0.31 as I do for my projects in Eclipse. That's what the sysadmin gave me to deploy my apps so I can't switch to anything else.

I download the newest Spring Tools 4 for Eclipse (4.18.0) and create a new Spring Starter Project. Default values are type "Gradle - Groovy", Java Version "17" and packaging "Jar", but I change them to "Maven", "11" and "War", respectively. I don't see any place where I can configure my Tomcat. I click Next, leave the field Spring Boot Version as it is (3.0.5) and click Finish.

It creates a Maven project, but Java Version is still 17 everywhere (JRE System Library, pom.xml). When I go to Boot Dashboard and start the demo project, I get Java Version 17.0.6 and Tomcat 10.1.7 in the output.

I try to change that manually:

Now when I go to Boot Dashboard and start the demo project, I get the exception Exception in thread "main" java.lang.UnsupportedClassVersionError: org/springframework/boot/SpringApplication has been compiled by a more recent version of the Java Runtime (class file version 61.0), this version of the Java Runtime only recognizes class file versions up to 55.0 which complains that it was expecting Java 17 but got Java 11.

I'm stuck with no more apparent options. Is Spring Boot supposed to work under a specific version so I should download an older Spring Tool Suite compatible with Java 11? I guess I'm doing/understanding something wrong.


Solution

  • As already mentioned in the comments, Spring Boot 3 has a minimum dependency on Java 17, that is why the tooling configures the created project to use Java 17 all across the place.

    Please select the latest Spring Boot 2.7 version, Maven as a build environment, Java 11, and the WAR packaging and you should be good to go.