In the ResourceConfig
, you can call packages("reource.packages")
, which will do the same as scanning the package declared inside the <init-param>
public class Config extends ResourceConfig {
public Config() {
packages("...");
register(new AbstractBinder()..);
}
}
To use the Config
class, you have a couple options.
Annotate it with @ApplicationPath("/appPath")
With this, no web.xml is required. You need to make sure you have the jersey-container-servlet
dependency for this to work. The value in the annotation works the same way as the <servlet-mapping>
inside the web.xml.
Declare the Config
class inside the web.xml
<servlet>
<servlet-name>MyApplication</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.foo.Config</param-value>
</init-param>
</servlet>
...
<servlet-mapping>
<servlet-name>MyApplication</servlet-name>
<url-pattern>/myPath/*</url-pattern>
</servlet-mapping>
You could also not use the ResourceConfig
and register the binder inside a Feature
, as discussed here
See Also: