Java – spring boot deployed in Tomcat provides 404 but works independently

I've been testing spring boot with embedded Tomcat for about a month to build a rest API Everything is fine We now want to deploy the API in a separate development environment with other (non spring) applications running on the Tomcat container

I made changes in converting a spring boot jar application to a war using Maven and spring boot docs

The deployment went well (the log was good and there were no errors). Looking at Tomcat management, I saw my application deployment But when I try to visit http://localhost:8080/sophia/users Curl I get 404

Thank you for any help

to update:

This is my log:

NetBeans:

Tomcat's:

And in Sophia Catalina local host in XML:

<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" docBase="/home/bugz/workspace/pdcore/sophiaserver/target/sophia-server-1.0.0-SNAPSHOT" path="/sophia"/>

I tried to visit

> http://localhost:8080/sophia/users > http://localhost:8080/sophia -server-1.0. 0-snapshot / users (name of war)

The first returns 404, but uses the CORS information of the CORS filter The second return 404 has no CORS information (indicating that the application has been started and configured, but I don't seem to have access to the controller)

Solution

When running an application, the call path consists of several parts

The first is the basic URL for application deployment, which in your case is / Sophia

The second is the servlet mapping of the dispatcher servlet of / sohpia / * in your case

The third is the controller mapping in the dispatcher servlet, which in your case is / users

All of these combinations create URLs / Sophia / Sophia / users

The difference between deployment as a war is that when you run as a jar, you will include a separate URL for deployment, which is deployed to / (root) by default

You can use / Sophia as the server Put context path in application Properties and map the dispatcher servlet to / * or / This will provide you with the required URL (and expected) in two cases

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>