简体   繁体   English

在多个ejb之间共享env-entry

[英]share env-entry between multiple ejb

I am currently working on a project with multiple ejb and one ejb-jar.xml. 我目前正在开发一个包含多个ejb和一个ejb-jar.xml的项目。 I wonder how to share the env-entry from the ejb-jar.xml between the various ejbs. 我想知道如何在各种ejbs之间共享ejb-jar.xml中的env-entry。

example : 例如:

I have the following ejb-jar.xml 我有以下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 : 在MyBeanA中我使用:

@Ressource
private SessionContext context;

I can get the value of myVar with the following code : 我可以使用以下代码获取myVar的值:

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

Is there a way to get the value of myVar in another ejb like MyBeanB ? 有没有办法在另一个像MyBeanB这样的ejb中获取myVar的值?

Thank you 谢谢

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. 将把它带到EG并交叉我的手指,为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/. 与此同时,如果您有耳朵,可以在application.xml中声明它们,它将在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. 如果在.war文件中有EJB,则可以在web.xml中执行,EJB可以在java:comp或java:module中查看它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM