share env-entry between multiple ejb
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 ?
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.
精彩评论