I'm trying to develop a RESTful webapp using the Servlet 3.0 Application class on Tomcat 7.0.34.0, but nothing seems to work. I've had no problem with previous apps using the Jersey ServletContainer approach and declaring all REST services in the web.xml.
My current Application sub-class:
package aaa;
@ApplicationPath("/test")
public class ApplicationConfig extends Application
{
@Override
public Set<Class<?>> getClasses ()
{
Set<Class<?>> resources = new java.util.HashSet<Class<?>> ();
resources.add (aaa.TestResource.class);
return resources;
}
}
and the web service:
package aaa;
@Path("test")
public class TestResource
{
public TestResource () {}
@GET
@Produces("text/html")
public String getXml ()
{
return "TEST SUCCESS";
}
}
When I try to deploy the app, Tomcat tells me the context has been reloaded:
INFO: Reloading Context with name [/WebApplication1] has started
Nov 10, 2013 7:06:25 PM org.apache.catalina.core.StandardContext reload
INFO: Reloading Context with name [/WebApplication1] is completed
The web app itself is deployed (I can access its JSP pages) - however, the "test" resource remains unavailable. I've tried every possible URL and get only 404 in response. It seems ApplicationConfig is never even loaded.
A point of interest: following the suggestions in this question, I've tried adding a small web.xml with no and removing the @ApplicationPath. The result is a NullPointerException, which is exactly the behaviour I would expect in a Servlet 2.x environment (no class specified, so the ClassLoader crashes).
I'm at a loss here. Any suggestion on what I'm doing wrong ?
PS: I'm using NetBeans 7.3.1, project is [Java Web -> Web Application -> Java EE 6 Web] with no extra library and no context/dependency injection.