简体   繁体   中英

Wildfly - How to startup bean before persistence is loaded?

I would like to execute some logic before Persistence Unit is loaded in Wildfly 8.0. I have a structure like this:

  • xxx.ear
    • before-persistence-bean.jar
    • beans.jar
    • xxx.war

beans.jar contains entity beans with persistence.XML and session beans

before-persistence-bean.jar contains one class:

@Startup
@Singleton
public class BeforePersistenceServiceBean {

    @PostConstruct
    public void performOperations() {...}

}

In application.xml I have:

<initialize-in-order>true</initialize-in-order>
<module>
    <ejb>before-persistence-bean.jar</ejb>
</module>
<module>
    <ejb>beans.jar</ejb>
</module>
<module>
    <web>
        <web-uri>xxx.war</web-uri>
        <context-root>/xxx</context-root>
    </web>
</module>

Now, after starting Wildfly I get error that:

service jboss.persistenceunit."xxx.ear/beans.jar#pu_name" (missing) dependents: 
[service jboss.deployment.subunit."xxx.ear"."before-persistence
bean.jar".component.BeforePersistenceServiceBean.START] 

But BeforePersistenceServiceBean doesn't have dependency on Persistence Unit, what is going on here ?

---EDIT---

After failing to deploy this bean before persistence kicks off, I have used solution similar to described in CDI Extension for Flyway (ie using Hibernate Integrator API)

Add a jboss-deployment-structure.xml to the META-INF directory if your EAR to indicate you want the subdeployments isolated .

I would imagine the contents would look something like

<subsystem xmlns="urn:jboss:domain:ee:1.0" >            
  <ear-subdeployments-isolated>false</ear-subdeployments-isolated>
  <sub-deployment name="xxx.war">
    <dependencies>
      <module name="deployment.xxx.ear.beans.jar" />
    </dependencies>
  </sub-deployment>
</subsystem>

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