Chapter 34. EJB Integration
To integrate with Enterprise JavaBeans (EJB), you must first modify your EJB's published interfaces. Currently, RESTEasy only has simple portable integration with EJBs, so you must manually configure your RESTEasy
WAR
.
To make an EJB a JAX-RS resource, annotate a stateless session bean's
@Remote
or @Local
interface with JAX-RS annotations, as follows:
@Local @Path("/Library") public interface Library { @GET @Path("/books/{isbn}") public String getBook(@PathParam("isbn") String isbn); } @Stateless public class LibraryBean implements Library { ... }
Next, in RESTEasy's
web.xml
, manually register the EJB with RESTEasy by using the resteasy.jndi.resources <context-param>
:
<web-app> <display-name>Archetype Created Web Application</display-name> <context-param> <param-name>resteasy.jndi.resources</param-name> <param-value>LibraryBean/local</param-value> </context-param> <listener> <listener-class>org.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class> </listener> <servlet> <servlet-name>Resteasy</servlet-name> <servlet-class>org.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class> </servlet> <servlet-mapping> <servlet-name>Resteasy</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> </web-app>
At present, this is the only portable integration method for EJBs. Future versions of RESTEasy will be more tightly integrated with JBoss AS, so manual registrations and modifications to
web.xml
will be unnecessary.
If you are using RESTEasy with an
EAR
and EJBs, the following structure is helpful:
my-ear.ear |------myejb.jar |------resteasy-jaxrs.war | ----WEB-INF/web.xml ----WEB-INF/lib (nothing) |------lib/ | ----All Resteasy jar files
Remove all libraries from
WEB-INF/lib
and place them in a common EAR
library, or place the RESTEasy JAR
dependencies in your application server's system classpath (that is, in JBoss AS, place them in server/default/lib
).