My understanding is that glassfish 3 is JEE6 compliant and jax-rs-aware, and that consequently I do not have to include the jersey servlet container and mapping in my web.xml file. Here's what I was hoping my web.xml could look like
<webapp>
</webapp>
That doesn't work though, as I get 404's when I try to hit my jax-rs path-anotated resources. It works great when I include the servlet adaptor, like this:
<webapp>
<servlet>
<servlet-name>ServletAdaptor</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servle
<load-on-startup&g开发者_如何学运维t;1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>ServletAdaptor</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</webapp>
Is it possible to have an empty webapp element using jersey on glassfish 3.0.1?
For Java EE 6 compliant JAX-RS implementations, I think you need to do the following:
- Add a
javax.ws.rs.core.Application
sub-class to your web project - Then, add a
@javax.ws.rs.ApplicationPath("/*")
annotation to the Application sub-class.
Your Application sub-class shouldn't have to do anything. By the spec this implies that any @Path/@Provider
found in the app will be included in the application and then your @ApplicationPath
is like your servlet mapping. This will let you have an empty web.xml.
The issue with having no web.xml is that a JAX-RS implementation will not know which servlet mapping (url pattern) to use. Also, this allows you to have only certain resources/providers available for a particular URL pattern if you wish to return only a subset of @Path
/@Provider
annotated classes in your Application.getClasses()
.
Processing of web-fragment.xml files is probably only supported when you declare the correct version in your web.xml. This way the behaviour of existing applications don't suddenly change when deployed to a new version of an application server.
Please try it with a web.xml like this, which is copied from a newly created ee6 web project in Netbeans.
<web-app version="3.0"
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">
</web-app>
精彩评论