Spring boot not running on external Tomcat 10
Asked Answered
W

5

9

Spring boot not running on external tomcat

I have previously worked with Spring Boot on Java 1.8 and Tomcat 8. I recently started a new project where I upgraded to Java 17, Tomcat 10.

I'm trying to deploy as a war to run in an external tomcat, but it doesn't work.

I ran and deployed the project without any problems in the existing Java 1.8 and Tomcat 8 in the actual production environment. I think you know how to deploy spring boot as war.

I have read the Spring Boot official documentation at the link below. https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto.traditional-deployment.war

My project's pom.xml has the settings below applied.

<packaging>war</packaging>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-tomcat</artifactId>
   <scope>provided</scope>
</dependency>

And

<configuration>
   <mainClass>mypackage.SpringBootCoreApplication</mainClass>
</configuration>

And SpringBootApplication is also configured.

@SpringBootApplication
public class SpringBootCoreApplication extends SpringBootServletInitializer {

   @Override
   protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
      return application.sources(SpringBootCoreApplication.class);
   }

   public static void main(String[] args) {
      SpringApplication.run(SpringBootCoreApplication.class, args);
   }

}

Now, I ran Tomcat to deploy as war, and the following log came out.

31-Oct-2022 19:52:47.382 INFO [main] org.apache.jasper.servlet.TldScanner.scanJars At least one JAR was scanned for TLDs yet contained no TLDs. Enable debug logging for this logger for a complete list of JARs that were scanned but no TLDs were found in them. Skipping unneeded JARs during scanning can improve startup time and JSP compilation time.
31-Oct-2022 19:52:43.818 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/ROOT.war]
31-Oct-2022 19:52:43.780 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet engine: [Apache Tomcat/10.1.1]
31-Oct-2022 19:52:43.779 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
31-Oct-2022 19:52:43.686 INFO [main] org.apache.catalina.startup.Catalina.load Server initialization in [961] milliseconds
31-Oct-2022 19:52:43.618 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
31-Oct-2022 19:52:43.069 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 3.0.2 15 Mar 2022]
31-Oct-2022 19:52:43.063 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded Apache Tomcat Native library [2.0.1] using APR version [1.7.0].
31-Oct-2022 19:52:43.059 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
31-Oct-2022 19:52:43.059 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
31-Oct-2022 19:52:43.059 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
31-Oct-2022 19:52:43.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dorg.apache.catalina.security.SecurityListener.UMASK=0027
31-Oct-2022 19:52:43.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
31-Oct-2022 19:52:43.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
31-Oct-2022 19:52:43.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
31-Oct-2022 19:52:43.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
31-Oct-2022 19:52:43.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
31-Oct-2022 19:52:43.058 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util.concurrent=ALL-UNNAMED
31-Oct-2022 19:52:43.057 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.util=ALL-UNNAMED
31-Oct-2022 19:52:43.057 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.io=ALL-UNNAMED
31-Oct-2022 19:52:43.057 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: --add-opens=java.base/java.lang=ALL-UNNAMED
31-Oct-2022 19:52:43.033 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
31-Oct-2022 19:52:43.033 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
31-Oct-2022 19:52:43.033 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Eclipse Adoptium
31-Oct-2022 19:52:43.032 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           17.0.4.1+1
31-Oct-2022 19:52:43.032 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /opt/java/openjdk
31-Oct-2022 19:52:43.031 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
31-Oct-2022 19:52:43.031 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.4.180+
31-Oct-2022 19:52:43.031 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
31-Oct-2022 19:52:43.030 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version number: 10.1.1.0
31-Oct-2022 19:52:43.030 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Oct 3 2022 12:42:14 UTC
31-Oct-2022 19:52:43.017 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version name:   Apache Tomcat/10.1.1
NOTE: Picked up JDK_JAVA_OPTIONS:  --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.io=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.rmi/sun.rmi.transport=ALL-UNNAMED
Using CATALINA_OPTS:   
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Using JRE_HOME:        /opt/java/openjdk
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_BASE:   /usr/local/tomcat
31-Oct-2022 19:52:41.636 INFO [Thread-1] org.apache.coyote.AbstractProtocol.destroy Destroying ProtocolHandler ["http-nio-8080"]
31-Oct-2022 19:52:41.627 INFO [Thread-1] org.apache.coyote.AbstractProtocol.stop Stopping ProtocolHandler ["http-nio-8080"]
31-Oct-2022 19:52:41.612 INFO [Thread-1] org.apache.catalina.core.StandardService.stopInternal Stopping service [Catalina]
31-Oct-2022 19:52:41.608 INFO [Thread-1] org.apache.coyote.AbstractProtocol.pause Pausing ProtocolHandler ["http-nio-8080"]
31-Oct-2022 19:48:16.236 INFO [Catalina-utility-2] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/ROOT.war] has finished in [4,098] ms

Spring Boot as I remember it doesn't end up with logs like this. The project is running but spring boot doesn't seem to be running.

The log shows that it was successful, but it doesn't actually connect.

I read the official Spring Boot documentation, many questions/answers, and blog posts, but I couldn't solve it.

I don't know what I have configured wrong. please help me

Welford answered 31/10, 2022 at 21:59 Comment(5)
What version of Spring? Tomcat 10 uses the JakartaEE namespace - you’d need to be using Spring Boot 3.X for that to work - more specifically Spring Framework 6.X.Salol
@BoristheSpider I am using spring boot 2.7.2 (spring 5.3.22). Is there anything else I should check?Welford
You can use Tomcat Manager App to check if your app is deployed correctly.Asben
@Welford no. Nothing more. You need to downgrade Tomcat to a version using the JavaEE namespace.Salol
@BoristheSpider Thanks for your comment. I found the reason and solved it thanks to you.Welford
W
20

I found the reason. I am writing this for those of you who are struggling for the same reason.

Upgrading to Tomcat 10 was a problem.

Tomcat10 is an implementation of the JakartaEE specification that is not currently supported. Spring (and Spring Boot) currently only supports JavaEE, not JakartaEE. Jakarta EE support is planned for Spring6 and SpringBoot3 expected later this year.

There are two options.

  1. Deploy the war to the webapps-javaee directory instead of the webapps directory. Tomcat uses a conversion tool to convert automatically. I solved the same problem with this.
  2. Using Tomcat 9 with Java EE support
Welford answered 1/11, 2022 at 8:4 Comment(1)
How do you automatically deploy the war to webapps-javaee directory? Did you create any separate script for it?Fruge
D
3

I was having the same issue. Then I have upgraded Spring Boot version to 3.1.0 and it started working no need to deploy it in webapps-javaee folder. Deploy normally in webapps folder it will work.

<parent>
     <groupId>org.springframework.boot</groupId>
     <artifactId>spring-boot-starter-parent</artifactId>
     <version>3.1.0</version>
   </parent>

<properties>
        <java.version>17</java.version>
</properties>
Derangement answered 8/6, 2023 at 9:53 Comment(0)
P
1

it worked for me with java 20 and spring version 3.1.0 and tomcat 10.1.13. I didn't need to create the webapps-javaee directory

<parent>
 <groupId>org.springframework.boot</groupId>
 <artifactId>spring-boot-starter-parent</artifactId>
 <version>3.1.0</version>
<java.version>20</java.version>
Purehearted answered 15/9, 2023 at 20:39 Comment(0)
B
0

Deploying the war to the webapps-javaee directory instead of the webapps directory worked for me.

Brumal answered 13/1, 2023 at 7:51 Comment(1)
How do we automatically deploy the war to webapps-javaee directory? Did you create any separate script for it?Fruge
A
0

Deploying the war to the webapps-javaee directory instead of the webapps directory worked. Therefore the problem with deplyment on Tomcat 10 worked!!!

Ardoin answered 12/2, 2023 at 3:2 Comment(1)
How do we automatically deploy the war to webapps-javaee directory? Did you create any separate script for it?Fruge

© 2022 - 2024 — McMap. All rights reserved.