Java Reference
In-Depth Information
set . add ( json );
set . add ( service );
return
return set ;
}
}
The @ApplicationPath annotation here will set up a base path to whatever the WAR's con-
text root is, with root appended.
You can fully leverage the servlet class scanning abilities if you have both getClasses()
and getSingletons() return an empty set. For example:
package
package com . restfully . shop . services ;
import
import javax.ws.rs.core.Application
javax.ws.rs.core.Application ;
import
import javax.ws.rs.ApplicationPath
javax.ws.rs.ApplicationPath ;
@ApplicationPath ( "/root" )
public
public class
class ShoppingApplication
ShoppingApplication extends
extends Application {
// complete
}
When scanning, the application server will look within WEB-INF/classes and any JAR file
within the WEB-INF/lib directory. It will add any class annotated with @Path or @Provider
to the list of things that need to be deployed and registered with the JAX-RS runtime. You
can also deploy as many Application classes as you want in one WAR. The scanner will
also ignore any Application classes not annotated with @ApplicationPath .
You can also override the @ApplicationPath annotation via a simple servlet mapping with-
in web.xml :
<?xml version="1.0" encoding="UTF-8"?>
<web-app
<web-app 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"
version= "3.0" >
<servlet-mapping>
<servlet-mapping>
<servlet-name>
<servlet-name> com.rest.ShoppingApplication </servlet-name>
</servlet-name>
<url-pattern>
<url-pattern> /* </url-pattern>
</url-pattern>
</servlet-mapping>
</web-app>
Search WWH ::




Custom Search