Ce contenu n'est pas disponible dans la langue sélectionnée.

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 {

...

}
Copy to Clipboard Toggle word wrap
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>
Copy to Clipboard Toggle word wrap
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
Copy to Clipboard Toggle word wrap
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).
Retour au début
Red Hat logoGithubredditYoutubeTwitter

Apprendre

Essayez, achetez et vendez

Communautés

À propos de la documentation Red Hat

Nous aidons les utilisateurs de Red Hat à innover et à atteindre leurs objectifs grâce à nos produits et services avec un contenu auquel ils peuvent faire confiance. Découvrez nos récentes mises à jour.

Rendre l’open source plus inclusif

Red Hat s'engage à remplacer le langage problématique dans notre code, notre documentation et nos propriétés Web. Pour plus de détails, consultez le Blog Red Hat.

À propos de Red Hat

Nous proposons des solutions renforcées qui facilitent le travail des entreprises sur plusieurs plates-formes et environnements, du centre de données central à la périphérie du réseau.

Theme

© 2025 Red Hat