2 Replies Latest reply on Jan 26, 2007 1:18 PM by Andrew Rubinger

    how to inject dependency on an mbean

    mr662 Newbie

      I have an mbean deployed in a ejb2.1 jar file. Here is the deployment descriptor.

      <mbean code="myapp.status.ClusterStatus"

      I am writing a ejb3 MDB which depends on above mbean. How do I inject dependency on the mbean.

      I have tried following inside MDB, but it does not work
      @Resource (mappedName="myapp:service=ClusterStatus")
      ClusterStatus clusterStatus;

      I get the error
      javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: myapp:service=ClusterStatus not bound]

      What is the correct way to inject dependency on an MBean?

        • 1. Re: how to inject dependency on an mbean
          mr662 Newbie

          Ok. I found the answer in ejb3 trailblazer. The trail on JMX Service Objects talk about how to annotate a service that depends on other services using @Depends tag. I guess the same holds true for EJBs as well, i.e. if an EJB depends on a service, use @Depends tag. I used following to make it work in my case:

          ClusterStatusMBean clusterStatusMbean = null;
          @Depends ("myapp:service=ClusterStatus")
          public void setClusterStatusMbean (ClusterStatusMBean mbean) {
           this.clusterStatusMbean = mbean;

          • 2. Re: how to inject dependency on an mbean
            Andrew Rubinger Master

            In @Resource injection, the value "mappedName" attribute should be the JNDI name of the resource, not the service name. :)


            @Resource(mappedName = "java:/jdbc/myapp/myDs")
            private DataSource myDs;