Dieser Inhalt ist in der von Ihnen ausgewählten Sprache nicht verfügbar.

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.
Nach oben
Red Hat logoGithubredditYoutubeTwitter

Lernen

Testen, kaufen und verkaufen

Communitys

Über Red Hat Dokumentation

Wir helfen Red Hat Benutzern, mit unseren Produkten und Diensten innovativ zu sein und ihre Ziele zu erreichen – mit Inhalten, denen sie vertrauen können. Entdecken Sie unsere neuesten Updates.

Mehr Inklusion in Open Source

Red Hat hat sich verpflichtet, problematische Sprache in unserem Code, unserer Dokumentation und unseren Web-Eigenschaften zu ersetzen. Weitere Einzelheiten finden Sie in Red Hat Blog.

Über Red Hat

Wir liefern gehärtete Lösungen, die es Unternehmen leichter machen, plattform- und umgebungsübergreifend zu arbeiten, vom zentralen Rechenzentrum bis zum Netzwerkrand.

Theme

© 2025 Red Hat