14 Replies Latest reply: Jul 29, 2011 9:56 AM by jaikiran pai RSS

App deploys fine in AS 6 CR1, but not in AS 6 Final (Dependency resolution)

Frank Bitzer Newbie

Hi guys,

 

I've a problem regarding dependency resolution in JBoss AS 6.0 Final. In our EAR that consists of several ejb-jar modules, we declare some stateless session beans with local and/or remote interfaces (using @Statless, @Local, @Remote etc.). Some of those session beans are injected into each other using the @EJB annotation. We also use some EJB 3.1 features such as @Singleton. The ejb-jar.xml looks like this:

 

<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar 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/ejb-jar_3_1.xsd"
    version="3.1">


</ejb-jar>

 

Now when I deploy the EAR in JBoss AS 6.0 CR1 (and M4 as well), it tries to build a "tree" of the beans to be able to deploy them in the right order. The log says for example:

 

13:59:16,888 INFO  [JBossASKernel] Created KernelDeployment for: controller.jar
13:59:16,888 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=nimbus.ear,jar=controller.jar,name=MetadataFacadeBean,service=EJB3
13:59:16,888 INFO  [JBossASKernel]   with dependencies:
13:59:16,888 INFO  [JBossASKernel]   and demands:
13:59:16,888 INFO  [JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described
13:59:16,888 INFO  [JBossASKernel]     jndi:nimbus/InstanceServiceBean/local-cloud.controller.service.api.InstanceService; Required: Described
13:59:16,888 INFO  [JBossASKernel]   and supplies:
13:59:16,888 INFO  [JBossASKernel]     jndi:MetadataFacadeBean
13:59:16,888 INFO  [JBossASKernel]     Class:cloud.controller.facade.api.MetadataFacade
13:59:16,889 INFO  [JBossASKernel]     jndi:nimbus/MetadataFacadeBean/remote
13:59:16,889 INFO  [JBossASKernel]     jndi:nimbus/MetadataFacadeBean/remote-cloud.controller.facade.api.MetadataFacade
13:59:16,889 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=nimbus.ear,jar=controller.jar,name=MetadataFacadeBean,service=EJB3) to KernelDeployment of: controller.jar

 

That's fine! The beans injected with @EJB are recognized and listed in the "and demands:" section.

 

BUT when I deploy exactly the same application to JBoss AS 6.0 Final it fails detecting the dependencies of the beans. The log now looks like this:

 

14:01:15,178 INFO  [JBossASKernel] Created KernelDeployment for: controller.jar
14:01:15,178 INFO  [JBossASKernel] installing bean: jboss.j2ee:ear=nimbus.ear,jar=controller.jar,name=MetadataFacadeBean,service=EJB3
14:01:15,178 INFO  [JBossASKernel]   with dependencies:
14:01:15,178 INFO  [JBossASKernel]   and demands:
14:01:15,178 INFO  [JBossASKernel]     jboss.ejb:service=EJBTimerService; Required: Described
14:01:15,178 INFO  [JBossASKernel]     jboss-switchboard:appName=nimbus,module=controller; Required: Create
14:01:15,178 INFO  [JBossASKernel]     jboss-injector:topLevelUnit=nimbus.ear,unit=controller.jar,bean=MetadataFacadeBean; Required: Described
14:01:15,178 INFO  [JBossASKernel]   and supplies:
14:01:15,179 INFO  [JBossASKernel]     jndi:MetadataFacadeBean
14:01:15,179 INFO  [JBossASKernel]     Class:cloud.controller.facade.api.MetadataFacade
14:01:15,179 INFO  [JBossASKernel]     jndi:nimbus/MetadataFacadeBean/remote
14:01:15,179 INFO  [JBossASKernel]     jndi:nimbus/MetadataFacadeBean/remote-cloud.controller.facade.api.MetadataFacade
14:01:15,179 INFO  [JBossASKernel] Added bean(jboss.j2ee:ear=nimbus.ear,jar=controller.jar,name=MetadataFacadeBean,service=EJB3) to KernelDeployment of: controller.jar

 

Especially note the difference in the "and demands" section! Because no "demands" are determined, the beans are deployed in a rather random order. And sometimes, this random order is wrong, because A is deployed before B, but B is injected into A via @EJB.

 

Now I wonder about the differences in the deployment mechanisms of JBoss AS 6 CR1 (and below) compared to JBoss AS 6 Final? Is there anything special that got changed?

 

Cheers,
Frank

  • 1. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final
    jaikiran pai Master

    Things have changed with respect to injection in 6.0 Final. But we expect the injection to work. Can you post the errors (if any) and the bean code? Also, is that really an empty ejb-jar.xml (i.e. you just have the ejb-jar element in there)? If so, then you can safely remove that ejb-jar.xml.

  • 2. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final
    Frank Bitzer Newbie

    Well, sometimes it works but sometimes it fails when initializing the @Singleton/@Startup bean (I guess this is because it gets deployed before its dependencies are deployed). An example exception is:

     

    14:01:26,613 ERROR [CMTTxInterceptor] javax.ejb.EJBTransactionRolledbackException: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: EntityServiceBean not bound]]
    14:01:26,616 ERROR [AbstractKernelController] Error installing to Start: name=startup-singleton-initiator:topLevelUnit=nimbus.ear,unit=controller.jar,bean=StartUpServiceBean aliases=[startup-singleton-initiator:bean=StartUpServiceBean,topLevelUnit=nimbus.ear,unit=controller.jar] state=Create: java.lang.RuntimeException: Could not invoke PostConstruct on the newly created bean instance
        at org.jboss.ejb3.singleton.impl.container.SingletonEJBInstanceManagerImpl.create(SingletonEJBInstanceManagerImpl.java:137) [:1.0.0-alpha-28]
        at org.jboss.ejb3.singleton.impl.container.SingletonEJBInstanceManagerImpl.get(SingletonEJBInstanceManagerImpl.java:152) [:1.0.0-alpha-28]
        at org.jboss.ejb3.singleton.deployer.StartupSingletonInitiator.start(StartupSingletonInitiator.java:84) [:1.0.0-alpha-28]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [:1.6.0_22]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [:1.6.0_22]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [:1.6.0_22]


    .

    . (long long stack )

    .


    Caused by: org.jboss.injection.manager.spi.InjectionException: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: EntityServiceBean not bound]]
        at org.jboss.injection.injector.EEInjector.inject(EEInjector.java:87) [:1.0.0-alpha-6]
        at org.jboss.injection.manager.core.DefaultInjectionContext.proceed(DefaultInjectionContext.java:58) [:1.0.0-alpha-6]
        at org.jboss.injection.manager.core.DefaultInjectionManager.inject(DefaultInjectionManager.java:58) [:1.0.0-alpha-6]
        at org.jboss.injection.manager.core.DefaultInjectionManager.inject(DefaultInjectionManager.java:64) [:1.0.0-alpha-6]
        at org.jboss.ejb3.injection.InjectionInvocation.invokeTarget(InjectionInvocation.java:140) [:1.7.17]
        at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:125) [:1.7.17]
        at org.jboss.ejb3.core.context.CurrentInvocationContextInterceptor.invoke(CurrentInvocationContextInterceptor.java:47) [:1.7.17]
        at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:116) [:1.7.17]
        at org.jboss.aspects.currentinvocation.CurrentInvocationInterceptor.invoke(CurrentInvocationInterceptor.java:67) [:1.0.1]
        at org.jboss.ejb3.injection.InjectionInvocation.invokeNext(InjectionInvocation.java:116) [:1.7.17]
        at org.jboss.ejb3.EJBContainer.injectBeanContext(EJBContainer.java:1363) [:1.7.17]
        at org.jboss.ejb3.stateless.StatelessContainer.createBeanContext(StatelessContainer.java:139) [:1.7.17]
        at org.jboss.ejb3.pool.AbstractPool.createBeanContext(AbstractPool.java:94) [:1.7.17]
        at org.jboss.ejb3.pool.AbstractPool.create(AbstractPool.java:81) [:1.7.17]
        at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:62) [:1.7.17]
        at org.jboss.ejb3.InfinitePool.get(InfinitePool.java:57) [:1.7.17]
        at org.jboss.ejb3.pool.ThreadlocalPool.create(ThreadlocalPool.java:54) [:1.7.17]
        at org.jboss.ejb3.pool.ThreadlocalPool.get(ThreadlocalPool.java:86) [:1.7.17]
        at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:58) [:1.7.17]
        at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:102) [jboss-aop.jar:2.2.1.GA]
        at org.jboss.ejb3.core.context.SessionInvocationContextAdapter.proceed(SessionInvocationContextAdapter.java:95) [:1.7.17]
        at org.jboss.ejb3.tx2.impl.CMTTxInterceptor.invokeInCallerTx(CMTTxInterceptor.java:223) [:0.0.1]
        ... 174 more
    Caused by: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: EntityServiceBean not bound]]
        at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1356) [:5.0.5.Final]
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:819) [:5.0.5.Final]
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:835) [:5.0.5.Final]
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688) [:5.0.5.Final]
        at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_22]
        at org.jboss.injection.injector.EEInjector.lookup(EEInjector.java:153) [:1.0.0-alpha-6]
        at org.jboss.injection.injector.EEInjector.inject(EEInjector.java:133) [:1.0.0-alpha-6]
        at org.jboss.injection.injector.EEInjector.inject(EEInjector.java:82) [:1.0.0-alpha-6]
        ... 195 more
    Caused by: javax.naming.NamingException: Could not dereference object [Root exception is javax.naming.NameNotFoundException: EntityServiceBean not bound]
        at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1356) [:5.0.5.Final]
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:819) [:5.0.5.Final]
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688) [:5.0.5.Final]
        at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_22]
        at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1350) [:5.0.5.Final]
        ... 202 more
    Caused by: javax.naming.NameNotFoundException: EntityServiceBean not bound
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:771) [:5.0.5.Final]
        at org.jnp.server.NamingServer.getBinding(NamingServer.java:779) [:5.0.5.Final]
        at org.jnp.server.NamingServer.getObject(NamingServer.java:785) [:5.0.5.Final]
        at org.jnp.server.NamingServer.lookup(NamingServer.java:396) [:5.0.5.Final]
        at org.jnp.server.NamingServer.lookup(NamingServer.java:399) [:5.0.5.Final]
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:728) [:5.0.5.Final]
        at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:688) [:5.0.5.Final]
        at javax.naming.InitialContext.lookup(InitialContext.java:392) [:1.6.0_22]
        at org.jnp.interfaces.NamingContext.resolveLink(NamingContext.java:1350) [:5.0.5.Final]
        ... 206 more

     

     

    Yes, the ejb-jar.xml is empty. I thought it was required in order to detect the ejb modules within the ear.

     

    The bean code is nothing special, just some examples:

     

    @Stateless
    @Remote(MetadataFacade.class)
    // We dont need transactions, as we only read informations.
    @TransactionAttribute(TransactionAttributeType.NEVER)
    public class MetadataFacadeBean implements MetadataFacade {

     

        @EJB
        private InstanceService instanceService;

     

        /**
         * {@inheritDoc}
         */
        @Override
        public InstanceDTO getInstanceDTO(String ipAddress, Long availabilityZoneId) {
            return instanceService.getInstanceDTO(ipAddress, availabilityZoneId);
        }

     

    }




    @Singleton
    @Startup
    public class StartUpServiceBean {

     

        /**
         * The Logger.
         */
        private static final Logger LOG = LoggerFactory.getLogger(StartUpServiceBean.class);

     

        /**
         * {@link SchemaVersionService}.
         */
        @EJB
        private transient SchemaVersionService schemaVersionService;

     

     

        @PostConstruct
        public void start() throws Exception {

     

            LOG.info("\n\nSTARTING APPLICATION SERVER - initializing data...\n\n");

     

            try {
                schemaVersionService.update();
            } catch (IncompatibleSchemaVersionException e) {
                LOG.error("--> start() unable to install a SchemaVersion: {}", e.toString());
            }

     

     

        }

     

    }

     

     

     

     

     

    @Stateless
    @Local(SchemaVersionService.class)
    public class SchemaVersionServiceBean implements SchemaVersionService {




        /**
         * The Entitiy Service bean.
         */
        @EJB
        private transient EntityServiceRemote entityService;



        /**
         * {@inheritDoc}
         */
        @Override
        public SchemaVersion update() throws IncompatibleSchemaVersionException {

         entityService.doSomething(...);

          ...

        }


    }

     


     

     

    Just let me know if you need further informations.

     

     

    Thanks,
    Fran

  • 3. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final
    jaikiran pai Master

    Can you the code for the EntityServiceBean which corresponds to:

     

    @EJB
        private  transient EntityServiceRemote entityService;

    what kind of a bean is that?

  • 4. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final
    Frank Bitzer Newbie

    Sure! There you go:

     

    @Stateless
    @Remote(EntityServiceRemote.class)
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public class EntityServiceBean implements EntityServiceRemote {


        /**
         * Instance of {@link CrudService} to handle entities.
         */
        @EJB(beanName = "CrudService")
        private CrudService crudService;


     

        /**
         * {@inheritDoc}
         */
        @Override
        public boolean doSomething() throws Exception {


            List<Contract> contracts = crudService.findByNamedQuery(Contract.ALL);


            return (contracts.size() == 0);


        }


    }


    public interface EntityServiceRemote extends EntityService {

       ... some additional methods to EntityService, not important here ...

    }


    public interface EntityService {


        public boolean doSomething() throws Exception;


    }



    @Local(CrudService.class)
    @Stateless(name = "CrudService")
    @TransactionAttribute(TransactionAttributeType.REQUIRED)
    public class CrudServiceBean extends AbstractCrudServiceBean implements CrudService {


          ...CRUD implementation, mostly contained in AbstractCrudServiceBean ...


    }

  • 5. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final
    jaikiran pai Master

    I think I know what's going on here. The startup singleton waits for a fully invokable ENC (i.e. for the @EJB SchemaVersionService) to be available. However, it doesn't take into account the transitive ENC dependency. i.e. it waits only for populated (but not fully invokable) ENC of SchemaVersionService. So the @Startup instance is created as soon as the ENC of SchemaVersionService (which contains the  @EJB EntityServiceRemote) is available. That explains the randomness of your error. The @Startup instance creation should actually wait till the (transitive) ENC of SchemaVersionService is fully invokable. This is a bug and i'll see how we can handle this.

     

    As a (ugly) workaround, just add an unused field to your @Startup @Singleton as follows:

     

    @Singleton
    @Startup
    public  class StartUpServiceBean {
    
        ....
    
        /**
         * {@link  SchemaVersionService}.
         */
        @EJB
        private transient  SchemaVersionService schemaVersionService;
    
    ...
       @EJB
       private EntityServiceRemote unusedEJB; // workaround for a bug in JBoss AS 6.0 Final
    

     

    That should get you past those random errors.

  • 6. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final (Dependency resolution)
    Michael Brackx Newbie

    Same problem here with a @Startup @Singleton with Local EJB dependencies.

    Jndi lookup fails because it is before the register.

     

    Additionally, the war is deployed to soon also resulting in failed jndi lookups.

  • 7. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final (Dependency resolution)
    jaikiran pai Master

    Michael Brackx wrote:

     

    Same problem here with a @Startup @Singleton with Local EJB dependencies.

    If it's similar to that transitive example that Frank posted, then yes it's a bug. If not, please post the details (preferably in a separate thread, so that we don't create a confusion).

  • 9. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final (Dependency resolution)
    mpulse_gregoire Newbie

    Hi

     

    I'm currently working on a migration of an application running on 4.2.2 to 6.0. The application still uses a lot of MBeans (still working with @Service @Management ... annotations). I know that  these annotations are more or less deprecated, but the deployment was working in CR1. Now I got same kind of problems as descibed in this post and the other one (Frank ones) with these MBeans. I got EJB injection problems. Even if I try to do the lookups mannually it only randomly works.

     

    In order to avoid the opening of other posts/issues, I presume my problem is also related to this bug (https://issues.jboss.org/browse/EJBTHREE-2227)?

     

    Thanks

    Greg

  • 10. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final (Dependency resolution)
    jaikiran pai Master

    mpulse_gregoire wrote:

     

    Now I got same kind of problems as descibed in this post and the other one (Frank ones) with these MBeans. I got EJB injection problems. Even if I try to do the lookups mannually it only randomly works.

     

    In order to avoid the opening of other posts/issues, I presume my problem is also related to this bug (https://issues.jboss.org/browse/EJBTHREE-2227)?

     

    If it's the similar kind of code (where a transitive @EJB comes into picture) then yes, it's the same issue. But please do create an EJBTHREE JIRA (since it's related to @Service which instantiates similar to @Startup @Singleton) with the details and any application that reproduces this issue.

  • 12. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final (Dependency resolution)
    klkoster Newbie

    It looks like this also occurs when a singleton EJB is packaged in a separate module than the EJB's it depends on, even though they are in the same EAR. In the case I have there are no transitive relationships in the depended upon EJB's (i.e. the JNDI of the references within the singleton are not bound when it starts).

  • 13. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final (Dependency resolution)
    jaikiran pai Master

    klkoster wrote:

     

    It looks like this also occurs when a singleton EJB is packaged in a separate module than the EJB's it depends on, even though they are in the same EAR. In the case I have there are no transitive relationships in the depended upon EJB's

    Please create a new thread, so that we can track that separately. Add relevant code, configs and exception stacktraces in that new thread.

  • 14. Re: App deploys fine in AS 6 CR1, but not in AS 6 Final (Dependency resolution)
    jaikiran pai Master

    Those of you following this thread, please try the latest AS6 nightly build (containing r111882) http://community.jboss.org/thread/161386 and see if it fixes the issue.