0 Replies Latest reply on Aug 2, 2012 10:02 AM by jose.a.g.g

    MBean Service dependencies does not work!!

    jose.a.g.g Newbie

      Hello everyone.


      I started to work with JBoss 7.1.1.Final recently (migration from 4.2.1.GA) and maybe it is a simple problem,

      but i can not find the solution.


      I'm working in a simple test deployment to check how to start a MBean service after a EJB in JBoss AS 7.1.1.Final,

      and I dont find the way to set the order of loading the different components.


      To introduce, I'm going to describe the structure of my ear:




      |-- lib

      |    |-- log4j-1.2.16.jar


      |-- META-INF

      |    |-- application.xml

      |    |-- jboss-app.xml

      |    |-- jboss-deployment-structure.xml

      |    |-- MANIFEST.MF


      |-- test-core.jar

      |-- test-ejb.jar

      |-- test-service.jar

      |-- test-sar.sar

            |-- META-INF

                  |-- jboss-service.xml


      NOTE: All the jars and the sar contains an empty file beans.xml inside the META-INF directory.


      test-core.jar contains the necessary code to manage the JBoss cluster. There is a principal class (ClusterManager) that injects:

      @Resource(lookup = "java:jboss/infinispan/container/cluster"). This class is annotated with @javax.annotation.ManagedBean and @javax.inject.Singleton.


      test-ejb.jar contains a simple class that represents a EJB with the next code:


      public class InitializationEJB {
          ClusterManager clusterManager;
          public void init() {
              System.out.println("The ClusterManager has been injected: " + clusterManager.getMasterNodeName());


      test-service.jar contains a simple MBean (and its interface) how this:


      public class StartInitializationService implements StartInitializationServiceMBean {
          ClusterManager clusterManager;
          public void start() {
              String result = null;
              if (clusterManager==null) {
                  result = "StartInitializationServiceMBean: The ClusterManager has not been injected.";
              } else {
                  result = "StartInitializationServiceMBean: The ClusterManager has been injected";
              result += "\n";
              // IMPORTANT: When the EJB initializes the ClusterManagager, it saves a reference internally
              // to get it with the getInstance() method.
              ClusterManager cm = ClusterManager.getInstance();
              if (cm == null) {
                  result += "StartInitializationServiceMBean: ClusterManager does not works with getInstance() method.";
              } else {
                  result += "StartInitializationServiceMBean: ClusterManager works with getInstance method!! MasterNodeName = " + cm.getMasterNodeName();
              return result;
          public void stop() {



      The content of my "application.xml" in the EAR:


      <application xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd">
          <module id="test-core">
          <module id="test-ejb">
          <module id="test-service">


      the content of my "jboss-app.xml" in the EAR:


      <?xml version="1.0" encoding="UTF-8"?>
      <jboss-app xmlns="http://www.jboss.com/xml/ns/javaee"
                   xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-app_7_0.xsd"


      and the content of my "jboss-service.xml" inside the sar:


      <?xml version="1.0" encoding="UTF-8"?>
      <server xmlns="urn:jboss:service:7.0"
            xsi:schemaLocation="urn:jboss:service:7.0 jboss-service_7_0.xsd">
           <mbean code="test.service.StartInitializationService" name="TestServices:service=StartInitializationService">



      Test 1: Deploy the EJB:

      If I deploy the ear without the sar, then the JBoss starts without errors and the EJB is deployed correctly.

      Using the Java Monitoring and Management Console I can see the object name of the EJB:


      and in the console I can see the message that verifies the ClusterManager has been injected.


      Test 2: Deploy EJB with SAR

      I add the dependency in the sar to the EJB, and take this error:


      JBAS014775:    New missing/unsatisfied dependencies:

            service jboss.mbean.service."jboss.as:deployment=test.ear,subdeployment=test-ejb.jar,subsystem=ejb3,singleton-bean=InitializationEJB".create (missing) dependents: [service jboss.mbean.service.TestServices:service=StartInitializationService.create]

            service jboss.mbean.service."jboss.as:deployment=test.ear,subdeployment=test-ejb.jar,subsystem=ejb3,singleton-bean=InitializationEJB".start (missing) dependents: [service jboss.mbean.service.TestServices:service=StartInitializationService.start]


      Test 3: Deploy EJB with SAR but without the depends:

      Removing the <depends> line of the sar, JBoss starts without problems and the MBean StartInitializationService is initialized.

      But the problem is that the MBean starts BEFORE the EJB was fully initialized (in this example does not occur because the load is small and

      starts at the same time, but if the EJB take a bit more time this would happen).

      Then, I can see in the console how the MBean starts before the EJB ends, and the ClusterManager is not yet initialized. Later, appears the message

      of the EJB starting the ClusterManager.


      Anyway, in all cases, the Inject in the MBean is null.

      If that inject loaded the ClusterManager, the EJB would no longer needed, but always is null. ¿is not possible to inject in a MBean indicated in the jboss-service.xml?

      I searched through many forums and community, but I find nothing that can fix this.


      Any ideas?


      Thanks in advance.