I'm trying to deploy a basic jersey restful service to Tomcat7 without web.xml:
@WebServlet(loadOnStartup=1)
@ApplicationPath("resources")
@Path("/mypath/{name}")
public class MyResource extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> s = new HashSet<Class<?>>();
s.add(MyResource.class);
return s;
}
@GET
@Consumes("text/plain")
@Produces("text/plain")
public String getWelcome(@PathParam(value = "name") String name) {
return "Welcome to jax-rs " + name;
}
}
I'm presented with a 404 when trying to access: /myapplication/resources/mypath/sample.
I can deploy a servlet using the @WebServlet
annotation, so this has nothing to do with the loading of servlets without web.xml into Tomcat7.
From reading the documentation for Jersey, the runtime should scan for classes extending Application
and execute getClasses()
, loading all root resources.