java:comp / env和java之间的关系是什么? [英] What is the relationship between java:comp/env and java:global?

查看:351
本文介绍了java:comp / env和java之间的关系是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

java:comp / env java:global (关于3.1规范)之间的关系? br>
似乎像 java:comp / env 包含特定于EJB引用。
在这种情况下,什么意思是具体?

What is the relationship between java:comp/env and java:global (regarding 3.1 spec)?
Seems like java:comp/env contains specific to EJB references. What means "specific" in this case?

推荐答案

java:全局是整个应用程序服务器的全局命名空间,其中包括其他EAR模块(被认为是不同的应用程序)。

java:global is a namespace that's global for the entire application server, which includes other EAR modules (which are considered to be different applications).

java:comp / env 是一个较小的命名空间。对于Web模块,它对应于所有一起被认为是JNDI的单个组件的Web组件(servlet等),但对于EJB bean,它是单个bean的命名空间,因为每个bean被认为是单独的组件。

java:comp/env is a much smaller namespace. For the web module, it corresponds to all web components (servlets etc) which are all together considered to be a single 'component' for JNDI, but for EJB beans it's a namespace for a single bean, since every bean is considered to be a separate component.

还有一个 java:app 和一个 java:module ,其范围在全局和comp之间。

There's also a java:app and a java:module, whose scopes fall between global and comp.

java:comp / env 而其他则是前者在运行时是严格只读的,并且包含注入到某个组件中的bean。例如考虑:

A big difference between java:comp/env and the others is that the former is strictly read-only at runtime and contains among others the beans that are injected into some component. So e.g. consider:

@Stateless 
public class ExampleBean {

    @EJB
    OtherBean testBean;

}

在这种情况下,注入到还可以从 java:comp / env 获取字段 testBean ,但只有当 java时: comp / env 在ExampleBean(JNDI是高度上下文)中引用。

In this case, the specific proxy that was injected into the field testBean can also be obtained from java:comp/env, but only when java:comp/env is referenced from within ExampleBean (JNDI is highly contextual).

如果你想要一个不同的EJB代理 OtherBean ,或者当没有注射完成时想要参考,你可以从任何其他范围获得这些参考。根据您正在从哪个类执行JNDI调用,您将可以使用较小的范围。

If you however wanted a different proxy to the EJB OtherBean, or wanted a reference when no injection had been done, you can get those from any of the other scopes. Depending on from which class you're doing the JNDI call, you would be able to use smaller scopes.

例如,如果 OtherBean 在与 ExampleBean 相同的模块中定义,您可以使用 java:module ,如果是相同的应用程序(但可能是不同的模块),您可以使用 java:app

For instance, if OtherBean is defined in the same module as ExampleBean, you could use java:module, if it's the same application (but possibly different modules) you can use java:app.

最后, java:global 总是安全使用,因为它不依赖于上下文。这意味着你可以从内部使用。一个非管理完全独立的线程。使用 java:global 的缺点是,如果使用EAR,则必须包含应用程序名称和模块名称,否则至少包含模块名称。

Finally, java:global is always safe to use, as it doesn't depend on the context. This means you could use from within e.g. a non-managed completely separate thread. The downside to using java:global is that you have to include the application name and the module name if an EAR is used, and otherwise at least the module name.

这篇关于java:comp / env和java之间的关系是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆