Search code examples
restweb-servicesspring-mvctomcat7jersey-2.0

jersey2 ws giving a 404 response


i'm trying to develop a basic RESTFULL application, i found some tutorials but i don't know what is going on because everything looks right. I'm launching the app with the maven tomcat plugin (if it helps).

Here are the web.xml and the controller.

    <servlet>
    <servlet-name>jersey-serlvet</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
         <param-name>jersey.config.server.provider.packages</param-name>
         <param-value>
            com.servicios.ws.controller
         </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>jersey-serlvet</servlet-name>
    <url-pattern>/ws/*</url-pattern>
</servlet-mapping>

and the controller

@Path("/ws/test")
public class UsuarioController {
    @GET
    @Path("/login")
    public final String findUsuarioById() {

        return "TEST OK";
    }
}

Finally, here you have the pom versions

<plugin>
                        <groupId>org.apache.tomcat.maven</groupId>
                        <artifactId>tomcat7-maven-plugin</artifactId>
                        <version>2.2</version>

                </plugin>

<dependency>
            <groupId>org.glassfish.jersey.containers</groupId>
            <artifactId>jersey-container-servlet</artifactId>
            <version>2.25</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.media</groupId>
            <artifactId>jersey-media-json-jackson</artifactId>
            <version>2.25</version>
        </dependency>

        <dependency>
            <groupId>org.glassfish.jersey.ext</groupId>
            <artifactId>jersey-spring3</artifactId>
            <version>2.25</version>
        </dependency>

It should work, but when i try to access the /ws/test/login, i get the 404.

Thanks in advance


Solution

  • Change @Path("/ws/test") to @Path("/test"). The ws in

    <url-pattern>/ws/*</url-pattern>
    

    gets prepended, so in its current state, you would need to access /ws/ws/test/login