gpt4 book ai didi

java - 什么是java :comp/env scope rules?

转载 作者:塔克拉玛干 更新时间:2023-11-03 03:55:39 25 4
gpt4 key购买 nike

我知道 java:comp/env 是 JNDI 树中的节点,您可以在其中找到当前 Java EE 组件(webapp 或 EJB)的属性,而且我也知道每个 EJB 都有自己的组件环境,还有 java:globaljava:app 和一个 java:module 取决于我有一些问题

  1. 当我使用 Context envContext = (Context)initContext.lookup("java:comp/env"); 获取 initContext 时,我得到的 Context 到底是什么(global、app、module、webApp 或 EJB上下文)?
  2. 是否有适用于搜索不同范围的特定规则?
  3. 假设我有一个包含许多 EJB 的 Web 应用程序,这是否意味着我有许多初始上下文(一个用于 webApp,一个用于每个 EJB),或者所有这些资源都以某种方式收集在一个上下文中 java:comp/环境?

非常感谢。

最佳答案

  1. 当我使用 Context envContext = (Context)initContext.lookup("java:comp/env");获取 initContext 我得到的上下文到底是什么(全局、应用程序、模块、webApp 或 EJB 上下文)?

引用自 TomEE 文档 http://tomee.apache.org/lookup-of-other-ejbs-example.html

In a webapp, the java:comp/env namespace is shared by all servlets. This is essentially equivalent to the java:module namespace in Java EE 6. Understand there is a conflict in definition here and that for EJBs, java:comp is scoped at the component (the EJB itself) not the module as with webapps.

  1. 是否有适用于搜索不同范围的特定规则?

引用自 JavaEE 6 教程 http://docs.oracle.com/cd/E19798-01/821-1841/girgn/index.html

The java:global JNDI namespace is the portable way of finding remote enterprise beans using JNDI lookups. The java:module namespace is used to look up local enterprise beans within the same module. The java:app namespace is used to look up local enterprise beans packaged within the same application. That is, the enterprise bean is packaged within an EAR file containing multiple Java EE modules.

  1. 假设我有一个包含许多 EJB 的 Web 应用程序,这是否意味着我有许多初始上下文(一个用于 webApp,一个用于每个 EJB),或者所有这些资源都以某种方式收集在一个上下文 java:comp/env 下?

Based on above links, you will have not have many contexts.

关于java - 什么是java :comp/env scope rules?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30210016/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com