Maven Tomcat plugin - 404 WebServlet not found

506 views Asked by At

I have a webapp with Maven which uses Tomcat plugin for the server. The app gets compiled to .war which, when extracted, seems to contain all classes (incl. servlets) in WEB-INF/classes folder.

When the url http://localhost:8080/com.galya.crm gets hit, index.html (which is a SPA app) gets loaded normally redirecting to http://localhost:8080/com.galya.crm/#!/login/msg/notlogged

I have 4 servlets annotated in a similar manner:

@WebServlet("/restapi/login")
public class LoginController extends HttpServlet {

The problem comes when the SPA app tries to authenticate using the login servlet (shown above). I expect it to be here: http://localhost:8080/com.galya.crm/restapi/login , but I get 404 error.

Below I attached the Tomcat plugin folder that is automatically created. Work directory is empty and I'm not sure if it's OK.

enter image description here

Initially the webapp/WEB-INF/web.xml was auto generated and contained the following:

<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>

I also tried to change it to accept WebServlet annotations, but didn't work also:

<!DOCTYPE web-app PUBLIC
    "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
     version="3.0">
</web-app>

P.S. The app was working on another server some time ago, so the problem should be in the server configurations, not in the code itself.

1

There are 1 answers

4
Little Santi On BEST ANSWER

Surely the cause is that the deployment descriptor must be declared to be of version 3.0. Your web.xml is still 2.3.

Remove the DOCTYPE declaration and leave the root node just as you already did:

<web-app 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

Tested myself, and it worked.