此内容没有您所选择的语言版本。

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.
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat