简体   繁体   中英

EJB depending on another EJB?

I'm using Jboss 7 and have two separate deployments that both contain singleton EJBs.

I need the one EJB to have access to the other EJB and be able to call its methods, however, when the app server starts up and attempts to deploy them both it seems to make no guarantees about which one gets started first (even if you set Dependencies: deployment.xxx.jar on one to the other).

I don't seem to be able to use the @DependsOn annotation, since this names a particular EJB which doesn't seem to be doable across separate deployments, leaving me with @EJB(lookup=JNDI_STRING) as my only option. This injection, however, doesn't seem to guarantee that the the EJB you're depending on will actually be started when the lookup happens, resulting in a NPE. Obviously, this also happens if you simply just use an InitialContext from the @PostContruct method to lookup the second EJB over JNDI.

So, I basically need to guarantee that one EJB in one deployment will be started before another EJB in another deployment, on the same appserver. I think it'd probably work if I were to lazily initialize the dependant EJB from, say, a HttpServlet set to run-on-startup, but this is not ideal.

Perhaps there's some sensible method of doing this that i'm missing? I don't really want to have to poll the EJB until it's started.

You can configure in the jboss-deployment-structure.xml

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
   <deployment>
       <dependencies>
           <module name="deployment.app1.ear" />
       </dependencies>
   </deployment>
</jboss-deployment-structure>

Source mastertheboss

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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