简体   繁体   中英

Tomcat deploys WAR file but application doesn't start in a docker container

I have a Spring Framework MVC application with annotations, it is packed with all depedencies. When tomcat/docker container is started, it deploys and upacks WAR file successfully but the application doesn't start. Catalina logs has the successfull startup and deploy line:

tomcat_1  | 29-Apr-2022 07:42:55.848 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/ROOT.war]
tomcat_1  | 29-Apr-2022 07:42:57.892 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.
tomcat_1  | 29-Apr-2022 07:42:57.948 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/ROOT.war] has finished in [2,099] ms

The application is packed without web.xml because it uses annotations.

Application starts without any issue in eclipse IDE and in a clean tomcat installion oustide docker.

Do you have any idea?

This is my DokerFiler

version: '3.9'
services:
  tomcat:
#    image: xxxxxxxxxxx
    image: tomcat:8-jre8-openjdk
    depends_on:
      - db
    ports:
      - '8082:8080'
    environment:
      DATABASE_URL: jdbc:mysql:/xxxxx
      MYSQL_USER: xxxx
      MYSQL_PASSWORD: xxxx
      MYSQL_DATABASE: xxxx
    volumes:
      - ./zzz:/usr/local/tomcat/webapps/
  db:
    image: mysql:5.7
    environment:
      MYSQL_ROOT_PASSWORD: xxx
      MYSQL_USER: xxxx
      MYSQL_PASSWORD: xxxx
      MYSQL_DATABASE: xxxx
    volumes:
      - .data:/var/lib/mysql
    ports:
      - "3309:3306"

I've been combating this issue for several days and concluded that this maybe the side effect of a slight incompatibility of the versions of Java with the versions of Tomcat that you have within the Docker image (in my case I did not manage to run <java.version>18</java.version> with standalone Tomcat v10 in container). So I just played around trying to find the exact combination of versions that will work out and this one solved the weird issue:

  1. I downgraded the image version of the tomcat container to tomcat:9.0.64-jre8
  2. Explicitly specified <java.version>1.8</java.version> in the pom.xml file

Remember that A) if you use Tomcat v.10 (not your case but anyways a frequent source of issues) you'll have to position your war file into webapps-javaee folder instead of webapps - this is a breaking change that Tomcat v10 introduced B) many other tutorials recommend just using an embedded Tomcat that comes along with Spring Boot and they don't expand on the standalone Tomcat

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM