Search code examples
spring-boottomcattomcat10

Why is upgrading to Tomcat 10.0.5 causing spring boot to shutdown after boot?


I have a spring boot project and I am trying to use Tomcat 10 embedded instead of Tomcat 7. I add the following to my POM...

<properties>
    <tomcat.version>10.0.5</tomcat.version>
    ...
</properties>

Then I run the same command I was running before...

mvn clean package -U && java -cp target\my.jar;props -Dloader.main=com.my.Main org.springframework.boot.loader.PropertiesLauncher

But now it just starts and then shuts itself down. The final messages are...

2021-05-13 15:35:42.105  INFO 10084 --- [           main] com.my.Main                   : Started Main in 42.918 seconds (JVM running for 44.009)
2021-05-13 15:35:42.190  INFO 10084 --- [extShutdownHook] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'

Why would this happen and how can I upgrade without this side effect?


Solution

  • Tomcat 10 is a Jakarta EE 9 servlet container. It basically means, that all javax.* packages were renamed to jakarta.* for copyright reasons (Oracle didn't allow the Eclipse Foundation to use the javax.* names).

    Spring Boot 2 and Spring 5 support only the previous Java EE 8 specification, you need to use Spring Boot 3 and Spring 6 for Tomcat 10 support. Alternatively you can pass Spring libraries through the Apache Tomcat Migration Tool or downgrade to Tomcat 9.0.

    See also