在多个 ejb 之间共享 env-entry

发布于 2024-10-03 12:50:56 字数 774 浏览 1 评论 0原文

我目前正在开发一个包含多个 ejb 和一个 ejb-jar.xml 的项目。我想知道如何在各个 ejb 之间共享 ejb-jar.xml 中的 env-entry。

示例:

我有以下 ejb-jar.xml

<session>
  <ejb-name>MyBeanA</ejb-name>
  <ejb-class>com.enterprise.MyBeanA</ejb-class>

  <env-entry>
    <env-entry-name>myVar</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>some value for my var</env-entry-value>
  </env-entry>
</session>

在 MyBeanA 中使用时:

@Ressource
private SessionContext context;

我可以使用以下代码获取 myVar 的值:

String myVar = (String) context.lookup("java:comp/env/myVar");

有没有办法在另一个 ejb(如 MyBeanB)中获取 myVar 的值?

I am currently working on a project with multiple ejb and one ejb-jar.xml. I wonder how to share the env-entry from the ejb-jar.xml between the various ejbs.

example :

I have the following ejb-jar.xml

<session>
  <ejb-name>MyBeanA</ejb-name>
  <ejb-class>com.enterprise.MyBeanA</ejb-class>

  <env-entry>
    <env-entry-name>myVar</env-entry-name>
    <env-entry-type>java.lang.String</env-entry-type>
    <env-entry-value>some value for my var</env-entry-value>
  </env-entry>
</session>

When in the MyBeanA I use :

@Ressource
private SessionContext context;

I can get the value of myVar with the following code :

String myVar = (String) context.lookup("java:comp/env/myVar");

Is there a way to get the value of myVar in another ejb like MyBeanB ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无边思念无边月 2024-10-10 12:50:56

唔。本来应该有一个程序集描述符的一部分,你可以在其中执行此操作,但我现在发现,在规范最终确定之前,我们一定错过了这一点。耻辱。将在 EG 中提出这个问题并祈祷现在修复 EJB.next 还为时不晚。

同时,如果您有兴趣,可以在 application.xml 中声明它们,并且它将在 java:app/ 中可用。如果 .war 文件中有 EJB,则可以在 web.xml 中执行此操作,并且 EJB 将能够在 java:comp 或 java:module 中看到它们。

Hmm. There was supposed to have been a section of the assembly-descriptor where you could do this, but I see now we must have missed that before the spec went final. Shame. Will bring that up in the EG and cross my fingers it isn't too late to fix for EJB.next.

In the meantime if you have an ear, you can declare them in the application.xml and it will be available in java:app/. If you have EJBs in a .war file, you can do it in the web.xml and the EJBs will be able to see them in either java:comp or java:module.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文