Getting Tomcat 404 error while trying to deploy simple hello spring boot app

Stephan Savchenko

I think I have similar problem, but don't know how to fix it Tomcat 404 error: The origin server did not find a current representation for the target resource or is not willing to disclose that one exists

Error image

I'm trying to build simple hello world spring boot app using docker and Tomcat. I made war file with maven, then put it to $CATALINA_HOME/webapps/ and started the server by performing ["catalina.sh", "run"]. But I still can't access to my app.

Tomcat status image

Error:

HTTP Status 404 – Not Found

Type Status Report

Message /demo/

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/9.0.2

Tomcat says, that my app is running

I tried to make another request to avoid wrong mapping http://localhost:8888/demo/hello http://localhost:8888/hello

Main class code:

@SpringBootApplication
@RestController
public class DemoApplication extends SpringBootServletInitializer {

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(DemoApplication.class);
    }
    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

    @GetMapping("/hello")
    public String hello() {
        return "Hello";
    }

}

Dockerfile

#
# for build
#
FROM maven:3.6.3-jdk-11-slim AS MAVEN_TOOL_CHAIN

COPY pom.xml /tmp/

COPY src /tmp/src/

WORKDIR /tmp/

RUN mvn package


#
# for deploy
#
FROM tomcat:9.0-alpine

MAINTAINER "admin"

USER root

# to get access to admin page
COPY /tomcat-users.xml $CATALINA_HOME/conf/tomcat-users.xml
COPY /settings.xml $CATALINA_HOME/conf/settings.xml
COPY /context.xml /usr/local/tomcat/webapps/manager/META-INF/

WORKDIR $CATALINA_HOME/webapps/

COPY --from=MAVEN_TOOL_CHAIN /tmp/target/demo-0.0.1-SNAPSHOT.war ./demo.war

EXPOSE 8080

CMD ["catalina.sh", "run"]

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>demo</name>
    <description>Demo project for Spring Boot</description>

    <properties>
        <java.version>11</java.version>
        <start-class>com.example.demo.DemoApplication</start-class>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
            <exclusions>
                <exclusion>
                    <groupId>org.junit.vintage</groupId>
                    <artifactId>junit-vintage-engine</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

</project>

Tomcats logs

26-Oct-2020 18:47:52.611 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server version:        Apache Tomcat/9.0.2
26-Oct-2020 18:47:52.613 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server built:          Nov 25 2017 21:08:02 UTC
26-Oct-2020 18:47:52.613 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Server number:         9.0.2.0
26-Oct-2020 18:47:52.613 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Name:               Linux
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log OS Version:            4.19.76-linuxkit
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Architecture:          amd64
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Java Home:             /usr/lib/jvm/java-1.8-openjdk/jre
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Version:           1.8.0_151-b12
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log JVM Vendor:            Oracle Corporation
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_BASE:         /usr/local/tomcat
26-Oct-2020 18:47:52.614 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log CATALINA_HOME:         /usr/local/tomcat
26-Oct-2020 18:47:52.615 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.config.file=/usr/local/tomcat/conf/logging.properties
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djdk.tls.ephemeralDHKeySize=2048
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.protocol.handler.pkgs=org.apache.catalina.webresources
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dignore.endorsed.dirs=
26-Oct-2020 18:47:52.617 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.base=/usr/local/tomcat
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Dcatalina.home=/usr/local/tomcat
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.startup.VersionLoggerListener.log Command line argument: -Djava.io.tmpdir=/usr/local/tomcat/temp
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent Loaded APR based Apache Tomcat Native library [1.2.16] using APR version [1.6.3].
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR capabilities: IPv6 [true], sendfile [true], accept filters [false], random [true].
26-Oct-2020 18:47:52.618 INFO [main] org.apache.catalina.core.AprLifecycleListener.lifecycleEvent APR/OpenSSL configuration: useAprConnector [false], useOpenSSL [true]
26-Oct-2020 18:47:52.622 INFO [main] org.apache.catalina.core.AprLifecycleListener.initializeSSL OpenSSL successfully initialized [OpenSSL 1.0.2n  7 Dec 2017]
26-Oct-2020 18:47:52.740 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["http-nio-8080"]
26-Oct-2020 18:47:52.756 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Oct-2020 18:47:52.766 INFO [main] org.apache.coyote.AbstractProtocol.init Initializing ProtocolHandler ["ajp-nio-8009"]
26-Oct-2020 18:47:52.767 INFO [main] org.apache.tomcat.util.net.NioSelectorPool.getSharedSelector Using a shared selector for servlet write/read
26-Oct-2020 18:47:52.768 INFO [main] org.apache.catalina.startup.Catalina.load Initialization processed in 607 ms
26-Oct-2020 18:47:52.795 INFO [main] org.apache.catalina.core.StandardService.startInternal Starting service [Catalina]
26-Oct-2020 18:47:52.795 INFO [main] org.apache.catalina.core.StandardEngine.startInternal Starting Servlet Engine: Apache Tomcat/9.0.2
26-Oct-2020 18:47:52.829 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deploying web application archive [/usr/local/tomcat/webapps/demo.war]
26-Oct-2020 18:47:54.207 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.
26-Oct-2020 18:47:54.332 INFO [main] org.apache.catalina.startup.HostConfig.deployWAR Deployment of web application archive [/usr/local/tomcat/webapps/demo.war] has finished in [1,502] ms
26-Oct-2020 18:47:54.334 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/manager]
26-Oct-2020 18:47:54.361 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/manager] has finished in [28] ms
26-Oct-2020 18:47:54.362 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/host-manager]
26-Oct-2020 18:47:54.384 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/host-manager] has finished in [22] ms
26-Oct-2020 18:47:54.384 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/examples]
26-Oct-2020 18:47:54.556 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/examples] has finished in [171] ms
26-Oct-2020 18:47:54.556 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/ROOT]
26-Oct-2020 18:47:54.568 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/ROOT] has finished in [12] ms
26-Oct-2020 18:47:54.569 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deploying web application directory [/usr/local/tomcat/webapps/docs]
26-Oct-2020 18:47:54.581 INFO [main] org.apache.catalina.startup.HostConfig.deployDirectory Deployment of web application directory [/usr/local/tomcat/webapps/docs] has finished in [12] ms
26-Oct-2020 18:47:54.585 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["http-nio-8080"]
26-Oct-2020 18:47:54.610 INFO [main] org.apache.coyote.AbstractProtocol.start Starting ProtocolHandler ["ajp-nio-8009"]
26-Oct-2020 18:47:54.612 INFO [main] org.apache.catalina.startup.Catalina.start Server startup in 1844 ms
26-Oct-2020 18:47:54.292 INFO [main] org.apache.catalina.core.ApplicationContext.log 1 Spring WebApplicationInitializers detected on classpath
26-Oct-2020 18:47:54.550 INFO [main] org.apache.catalina.core.ApplicationContext.log ContextListener: contextInitialized()
26-Oct-2020 18:47:54.550 INFO [main] org.apache.catalina.core.ApplicationContext.log SessionListener: contextInitialized()
Shawrup

The tomcat image you are using uses jdk8 as java version, but the war you are building uses java11. So tomcat is not deploying your app. Just use an tomcat jdk11 image and your app should start working.
You can use this image.

FROM tomcat:9.0-jdk11

To reduce vulnerabilities, the webapps folder in docker image will be empty, but the required folders to manager and other operations will be stored in webapps.dist folder. So if you need the manager and homepage ui , just copy the items from webapps.dist to webapps directory.

RUN cp -r $CATALINA_HOME/webapps.dist/* $CATALINA_HOME/webapps/

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

I'm getting error 404 while trying to access my spring boot app on Amazon Elastic Bean Stalk

Whitelabel Error on a simple Hello World app spring boot

Getting 404 error while trying to load the default page in Spring

Spring boot web app not working on Tomcat - 404 error

404 response while running simple hello restapi on tomcat

Spring Boot APP deploy to external tomcat

Getting error "APPLICATION FAILED TO START" with simple Spring Boot App

Spring Boot App returns 404 in remot Tomcat

Deploy Spring Boot to Tomcat

Spring Boot deploy with Tomcat

Getting 404 error when trying to login using Angular 6 & Spring Boot

A database name must be provided error when trying to deploy a spring boot app to google cloud

spring boot error 404 while starting jar

Getting error while trying to create react app

Why do I always get Whitelabel Error Page with status "404" while running a simple Spring Boot Application

Error while trying to deploy app on google app engine

Getting a 404 running local spring boot application on Tomcat 8

Deploy WAR file on Tomcat of Spring boot and Angular App

plan to deploy Spring boot app, which container is better, Jetty or tomcat?

Trying to Deploy a PCF Spring Boot App which requires a static IP

Google App Engine tomcat error with Spring Boot

Getting error while starting spring boot

deploy project from spring boot to tomcat, error in post form

Cant deploy simple Spring Boot web app to OpenShift

I keep getting this @bean error when trying to run my spring boot app with dynamodb and graphql

I am getting 404 error code while performing post request , but the data is successfully getting inserted into the database on spring boot appilcation

deploy spring boot war into tomcat

Error while trying to deploy the angular app in a azure vm:

PyObjc error while trying to deploy flask app on Heroku