Version 10
    Integration between RESTEasy and CDI is provided by the resteasy-cdi module. The module has been part of the JBoss AS since version 6.0.0 M4. It can also be used to integrate RESTEasy with any other CDI-complaint application server.

    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).


    This is the reason why you need to use the resteasy-cdi module. During a web service invocation, resteasy-cdi asks the CDI container for a managed instance of a JAX-RS component. Then, this instance is passed to RESTEasy.
    If a managed instance is not available for some reason (the class is placed in a jar which is not a bean deployment archive), RESTEasy falls back to instantiating the class itself.


    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.




    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



    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

    Resin-specific limitations

    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)