Is it possible to set up a JAX-RS application using annotations only? (using Servlet 3.0 and JAX-RS Jersey 1.1.0)
I tried and had no luck. Using some web.xml
seems required.
Configuration A (working, but has web.xml configuration)
web.xml
...
<servlet>
<servlet-name>org.foo.rest.MyApplication</servlet-name>
</servlet>
<servlet-mapping>
<servlet-name>org.foo.rest.MyApplication</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
...
Java
@ApplicationPath("/")
public class MyApplication extends Application {
...
}
Configuration B (not working, exception thrown)
@ApplicationPath("/")
@WebServlet("/*") // <--
public class MyApplication extends Application {
...
}
The latter seems to insist that the Application will be a subclass of Servlet (the exception leaves no guesswork)
java.lang.ClassCastException: org.foo.rest.MyApplication cannot be cast to javax.servlet.Servlet
Questions
Why the web.xml definition worked but the annotation didn't? What's the difference?
Is there a way to have it worked, e.g. have a JAX-RS Application with no web.xml?