Este contenido no está disponible en el idioma seleccionado.

Chapter 25. Configuring Individual JAX-RS Resource Beans


When you scan your path for JAX-RS annotated resource beans, your beans are registered in per-request mode. This means that an instance will be created for every HTTP request served. You will usually require information from your environment. If you run a WAR in a Servlet container with Beta 2 or lower, you can only use JNDI lookups to obtain references to Java EE resources and configuration information. In this case, define your EE configuration (that is, ejb-ref, env-entry, persistence-context-ref, etc.) in the web.xml of your RESTEasy WAR file. Then, within your code, perform JNDI lookups in the java:comp namespace. For example:
web.xml
<ejb-ref>
  <ejb-ref-name>ejb/foo</ejb-ref-name>
  ...
</ejb-ref>

Copy to Clipboard Toggle word wrap
Resource Code:
@Path("/")
public class MyBean {

   public Object getSomethingFromJndi() {
      new InitialContext.lookup("java:comp/ejb/foo");
   }
...
}
Copy to Clipboard Toggle word wrap
You can also configure and register your beans manually through the Registry. In a WAR-based deployment, you must write a specific ServletContextListener to do this. The listener lets you obtain a reference to the Registry, like so:
public class MyManualConfig implements ServletContextListener
{
   public void contextInitialized(ServletContextEvent event)
   {

      Registry registry = (Registry) event.getServletContext().getAttribute(Registry.class.getName());

   }
...
}

Copy to Clipboard Toggle word wrap
We recommend investigating Spring Integration and the Embedded Container's Spring Integration for a full understanding of this process.
Volver arriba
Red Hat logoGithubredditYoutubeTwitter

Aprender

Pruebe, compre y venda

Comunidades

Acerca de la documentación de Red Hat

Ayudamos a los usuarios de Red Hat a innovar y alcanzar sus objetivos con nuestros productos y servicios con contenido en el que pueden confiar. Explore nuestras recientes actualizaciones.

Hacer que el código abierto sea más inclusivo

Red Hat se compromete a reemplazar el lenguaje problemático en nuestro código, documentación y propiedades web. Para más detalles, consulte el Blog de Red Hat.

Acerca de Red Hat

Ofrecemos soluciones reforzadas que facilitan a las empresas trabajar en plataformas y entornos, desde el centro de datos central hasta el perímetro de la red.

Theme

© 2025 Red Hat