0 Replies Latest reply on Jan 17, 2008 7:50 AM by fredrik12471

    MBeanServerFactory problem using setter dependency injection

    fredrik12471

      I have been assigned to unit-test a smaller j2ee-application and when researching this I came across Embedded JBoss. Am I certainly not a JBoss-expert but during the ongoing research I have learnt a lot of things about J2EE and Jboss and using Embedded JBoss makes the unit-testing of EJB3 components go smooth.

      I have got most of the application working on Embedded JBoss during the research but I have now stumbled across a problem that I have difficulties solving.

      The application is being bootstrapped with several Mbeans and this is working fine, but when one of the Mbeans is calling a method on a stateless session bean in its start()-method I get an IndexOutOfBoundsException.

      What happens is that the Bootstrap-MBean is using dependency-injection with the @EJB-annotation to reach the stateless session bean, and this stateless session bean is using setter dependency injection with the @Depends annotation to be injected with another MBean. It is this injection that fails.

      @Depends(CoreServiceLocator.MBEAN_EVENT_SUBSCRIBER)
      public void setEventSubscriber(EventSubscriber subscriber) {
       this.eventSubscriber = subscriber;
      }



      Researching this gave me that the setter dependency injection in the stateless session bean is using the DependsMethodInjector-class to do the injection and in this class the line

      MBeanServer server = (MBeanServer) MBeanServerFactory.findMBeanServer(null).get(0);


      is throwing the IndexOutOfBoundsException.

      Apparently using the MBeanServerFactory.findMBeanServer is not doing any good in Embedded JBoss since it returns an empty list. Removing the @Depends annotation and doing a JNDI-lookup for the MBean is solving the problem but since this is not my code and it is working when deployed on a JBoss 4.2.1 server I do not want to make this change.

      I am currently researching this but something is missing and any pointers in the right direction would be very helpful.

      Many thanks,
      Fredrik