0

This Spring example uses a Java configuration to register a servlet. To test this,

  1. add a latest maven-war-plugin to ignore missing web.xml, and
<build>
    <plugins>
        <plugin>
            <artifactId>maven-war-plugin</artifactId>
            <version>3.2.2</version>
        </plugin>
    </plugins>
</build>
  1. build a war, and
  2. create a Dockerfile to use Tomcat, and
FROM tomcat

COPY example-05-dispatcher-servlet-code-configuration-2-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/
  1. build and run a container, and
docker build .
docker run -p 8080:8080 -it <image>
  1. send a request to /hello.
curl -4 -v -XGET http://localhost:8080/hello

However, the tomcat didn't find the controller, and this was what I got:

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

What did I wrong, and how can I fix it?

1 Answers1

1

My guess is that you miss the context path of the app which is the name of the folder inside /usr/local/tomcat/webapps/ that containing the exploded WAR . So in your case , please try :

curl -4 -v -XGET http://localhost:8080/example-05-dispatcher-servlet-code-configuration-2-1.0-SNAPSHOT/hello

If you really want to access by http://localhost:8080/hello , you have to deploy the WAR to /usr/local/tomcat/webapps/ROOT/. As the tomcat docker images already has a welcome page app deployed to this context , you need to delete this app first and rename your WAR to ROOT.war , something like :

FROM tomcat
RUN rm -rvf /usr/local/tomcat/webapps/ROOT
COPY example-05-dispatcher-servlet-code-configuration-2-1.0-SNAPSHOT.war /usr/local/tomcat/webapps/ROOT.war
Ken Chan
  • 84,777
  • 26
  • 143
  • 172
  • Thanks for your time! Unfortunately, `curl -4 -v -XGET http://localhost:8080/example-05-dispatcher-servlet-code-configuration-2-1.0-SNAPSHOT/hello` also gives me `404 NOT FOUND`. This is driving me crazy, haha. – eca2ed291a2f572f66f4a5fcf57511 Jan 22 '22 at 21:29