Search code examples
ejb-3.1wildfly-8jboss6.xmbeans

How to control order of deployment (EJB first and then MBeans deployment) in Wildfly 8.2.0 AS


I am migrating an EAR application containing MBeans from JBoss 6 AS to Wildfly 8.2.0 AS. In my EAR application, MBeans depend on EJB before initialization.

In JBoss 6 AS, @DependsOn annotation used in MBean maintained the sequence of the deployment i.e. Dependent EJB gets deployed and then, MBean gets deployed.

In Wildfly 8.2.0, I am trying to implement the same and @DependsOn is not working.

I tried the below in jboss-service.xml to have MBeans deployed only after the deployment of EAR file but this did not happen.

 <mbean code="sample.HelloWorldService" name="sample:service=HelloWorld,id=1">
    <depends>jboss.j2ee:service=EARDeployment,url='application.ear'</depends>
</mbean>

I also tried @startup in EJB but I cannot control the sequence i.e. 1. EJB deployment 2. MBeans deployment.

Can anyone please help about how to control the order of deployment in Wildfly 8.2.0. I need to deploy EJB first and then MBeans. Many thanks.


Solution

  • Just a comment

    About the EJB that you want to get from the MBeans, maybe you are misunderstanding the specificaction of jboss-deployment-structure.xml. It express an initialization dependency between singleton components (even if the related EJB are singleton be aware about possible problems with DependsOn like WLFY-4251).

    Workaround

    Due to you are working with Jboss/Wildfly Server, you have the option to use the jboss-deployment-structure.xml for specify dependency between modules. Perhaps, as your are packing all in the same EAR application, you can separate the components into modules, let's say one MBean.sar module that contains the MBeans and other RelatedEJBs.jar module with the EJBs referenced by your MBeans.

    Then you define the next dependency of MBeans.sar over RelatedEJBs.jar,

    <jboss-deployment-structure>
       ...
       <sub-deployment name="RelatedEJBs.jar">
         ...
       </sub-deployment>
       <sub-deployment name="MBeans.sar">
         <dependencies>
           <!-- Adds a dependency on the ejb jar. This could also be done with a Class-Path entry -->
           <module name="deployment.YouApp.ear.RelatedEJBs.jar" />
         </dependencies>
       </sub-deployment>
    </jboss-deployment-structure>
    

    Edit: A useful migration guide to Wildfly.