What is this module for?
It is important to realize that both JAX-RS and CDI specifications introduce its own component model. On the one hand, you only need to fulfill several basic constraints for your Java class to become a CDI managed bean. On the other hand, you need to explicitly decorate your Java class with @Path or @Provider annotation for it to become a JAX-RS resource or provider. What happens when you annotate a class that is suitable for being a CDI bean with JAX-RS annotations? RESTEasy and a CDI implementation start to compete and you do not get the desired result. (You end up having a JAX-RS component not managed by CDI).
Setting up an application
JBoss AS 6
The resteasy-cdi module has been bundled with JBoss AS since version 6.0.0 M4. Therefore, when using JBoss AS, there is no need to download the module separately or add any additional configuration.
Other JEE 6 containers
The configuration is quite straightforward. All you need to do is to add the resteasy-cdi module as a dependency.
<dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-cdi</artifactId> <version>${project.version}</version> <exclusions> <exclusion> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxrs</artifactId> </exclusion> </exclusions> </dependency>
Pre-Servlet 3 containers
Furthermore, if you are running a pre-Servlet 3 container (GAE with Weld), you need to specify the following context parameter in web.xml
<context-param> <param-name>resteasy.injector.factory</param-name> <param-value>org.jboss.resteasy.cdi.CdiInjectorFactory</param-value> </context-param>
Supported features
- CDI beans can serve as root resources, subresources, providers and application subclasses
- CDI beans which are JAX-RS root resources are @RequestScoped by default
- CDI beans which are providers or Application subclasses are @ApplicationScoped by default
Known limitations
General limitations
- if a Session Bean has more than one local interface, a random one is chosen for bean lookup
Weld(JBoss AS)-specific limitations
- constructor injection does not work with Session Beans (https://jira.jboss.org/jira/browse/WELDINT-31)
Resin-specific limitations
- JAX-RS property injection does not work (http://bugs.caucho.com/view.php?id=3967)
- JAX-RS setter injection does not work
- Session Beans do not work as JAX-RS components currently
- The module does not work with Resin 4.0.9 http://bugs.caucho.com/view.php?id=4182
Download & Source
You can download the resteasy-cdi .jar from JBoss Maven repository. Source code can be obtained from RESTEasy svn repository and built using Maven.
Tested environment
The RESTEasy-CDI module has been tested with the following application servers:
- JBoss AS 6 M4, M5, CR1
- Caucho Resin 4.0.5
- Google App Engine (see RESTEASY-392)
Comments