5 Replies Latest reply: Aug 31, 2011 2:35 PM by Michal Szynkiewicz RSS

    JMS, Spring and Snowdrop. Listening for an injection of bean factory to JNDI

    Michal Szynkiewicz Newbie

      Hi all,

       

      We are currently developing an application that uses an MDB to read messages from JMS and then delegates business logic to spring beans.

       

      All works fine if messages from JMS start getting delivered after all of the contexts are initialized. But when there are some messages in the queue during start time of the app, MDB is started earlier than bean factory is injected into JNDI and "bean factory not bound" exception is thrown when messages are delivered.

       

      Is there a generic solution to that problem? Can I make my EJBs "start" after bean factory is injected into JNDI?

       

      We thought that we can deliver MDB as inactive, than actively wait for application context to be injected into JNDI and than via JMX activate MDB, but it certainly is not an elegant solution.

       

      Is there a way to get notified that snowdrop has finished its work? Then we could write a simplier hack...

       

      Regards

      Michal

        • 1. Re: JMS, Spring and Snowdrop. Listening for an injection of bean factory to JNDI
          Marius Bogoevici Expert

          Michal,

           

          What version of JBoss AS  and Snowdrop/Spring Deployer is this?

           

          One approach could be to try setting up the priority of the Spring deployer to a lower value and ensure that the Spring Deployer runs first.

           

          But, anyway, can you just let me know how the beans are configured and what versions are you using?

           

          Thanks,

          Marius

          • 2. Re: JMS, Spring and Snowdrop. Listening for an injection of bean factory to JNDI
            Michal Szynkiewicz Newbie

            We use JBoss 5.1, Spring 3.0.5 and Snowdrop 1.1.0.GA (with Deployer 3.3).

             

            Whole app is deployed as EAR and it has one EJB module (it doesn't have a web module).

            The EJB module contains jboss-spring.xml that looks as follows:

            <?xml version="1.0" encoding="UTF-8"?>
            <beans xmlns="http://www.springframework.org/schema/beans"
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                       xmlns:context="http://www.springframework.org/schema/context"
                       xmlns:p="http://www.springframework.org/schema/p" xmlns:tx="http://www.springframework.org/schema/tx"
                       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
                            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.0.xsd"
                       xmlns:jee="http://www.springframework.org/schema/jee">
            
                    <description>BeanFactory=(OurBeanFactory)</description>
            
                    <import resource="classpath:META-INF/jmsConfig.xml" />
                                                                                                                                                                                        
                    <context:component-scan base-package="com.ourcompany"/>                                                                                                              
                    <tx:annotation-driven/>                                                                                                                                             
                                                                                                                                                                                        
                    <tx:jta-transaction-manager/>                                                                                                                                       
            
                     ...
            </beans>
            
            

            The EJB module also contains a Message Driven Bean which has two annotations: @Interceptors(SpringLifecycleInterceptor.class) and @MessageDriven and extends MessageListener.  Into that MDB we inject spring beans via:

            @Spring(jndiName = "OurBeanFactory", bean = "OurBeanName")
            

             

             

            How to set a deployer's priority?

             

            Thanks

            Michal

             

            Message was edited by: Michal Szynkiewicz Added missing citation marks

            • 3. Re: JMS, Spring and Snowdrop. Listening for an injection of bean factory to JNDI
              Michal Szynkiewicz Newbie

              I found relativeOrder property in deployer and changed it for spring deployers to -1 as follows:

                <bean name="SpringParserDeployer" class="org.jboss.spring.deployers.SpringParserDeployer">        <property name="relativeOrder">-1</property>
                 </bean>

                <bean name="ApplicationContextDeployer" class="org.jboss.spring.deployers.ApplicationContextDeployer">         <property name="relativeOrder">-1</property>    </bean>

               

              Is it safe to set relativeOrder value to -1? Is there any documentation to the relativeOrder parameter? I couldn't find any.

               

               

              I tried a greater value (5,6) because I thought that -1 can mean invocation before some crucial deployers, but it didin't work. I also tried to change the relativeOrder of ejb3 deployer but it caused following exception during JBoss startup:

              10:45:37,215 ERROR [AbstractKernelController] Error installing to Configured: name=Ejb3Deployer state=Instantiated
              java.lang.RuntimeException: Error configuring property: relativeOrder for Ejb3Deployer
                      at org.jboss.kernel.plugins.dependency.ConfigureAction.dispatchSetProperty(ConfigureAction.java:112)
                      at org.jboss.kernel.plugins.dependency.ConfigureAction.setAttributes(ConfigureAction.java:85)
                      at org.jboss.kernel.plugins.dependency.ConfigureAction.installActionInternal(ConfigureAction.java:44)
                      at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)
                      at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:42)
                      at org.jboss.dependency.plugins.action.SimpleControllerContextAction.simpleInstallAction(SimpleControllerContextAction.java:62)
                      at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:71)
                      at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)
                      at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
                      at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
                      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:774)
                      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:540)
                      at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:121)
                      at org.jboss.deployers.vfs.deployer.kernel.BeanMetaDataDeployer.deploy(BeanMetaDataDeployer.java:51)
                      at org.jboss.deployers.spi.deployer.helpers.AbstractSimpleRealDeployer.internalDeploy(AbstractSimpleRealDeployer.java:62)
                      at org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer.deploy(AbstractRealDeployer.java:50)
                      at org.jboss.deployers.plugins.deployers.DeployerWrapper.deploy(DeployerWrapper.java:171)
                      at org.jboss.deployers.plugins.deployers.DeployersImpl.doDeploy(DeployersImpl.java:1439)
                      at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1157)
                      at org.jboss.deployers.plugins.deployers.DeployersImpl.doInstallParentFirst(DeployersImpl.java:1178)
                      at org.jboss.deployers.plugins.deployers.DeployersImpl.install(DeployersImpl.java:1098)
                      at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
                      at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
                      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                      at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                      at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                      at org.jboss.deployers.plugins.deployers.DeployersImpl.process(DeployersImpl.java:781)
                      at org.jboss.deployers.plugins.main.MainDeployerImpl.process(MainDeployerImpl.java:702)
                      at org.jboss.system.server.profileservice.repository.MainDeployerAdapter.process(MainDeployerAdapter.java:117)
                      at org.jboss.system.server.profileservice.repository.ProfileDeployAction.install(ProfileDeployAction.java:70)
                      at org.jboss.system.server.profileservice.repository.AbstractProfileAction.install(AbstractProfileAction.java:53)
                      at org.jboss.system.server.profileservice.repository.AbstractProfileService.install(AbstractProfileService.java:361)
                      at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:348)
                      at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:1631)
                      at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:934)
                      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1082)
                      at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:984)
                      at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:822)
                      at org.jboss.dependency.plugins.AbstractController.change(AbstractController.java:553)
                      at org.jboss.system.server.profileservice.repository.AbstractProfileService.activateProfile(AbstractProfileService.java:306)
                      at org.jboss.system.server.profileservice.ProfileServiceBootstrap.start(ProfileServiceBootstrap.java:271)
                      at org.jboss.bootstrap.AbstractServerImpl.start(AbstractServerImpl.java:461)
                      at org.jboss.Main.boot(Main.java:221)
                      at org.jboss.Main$1.run(Main.java:556)
                      at java.lang.Thread.run(Thread.java:662)
              Caused by: java.lang.NullPointerException
                      at org.jboss.kernel.plugins.dependency.PropertyDispatchWrapper.execute(PropertyDispatchWrapper.java:111)
                      at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:47)
                      at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:109)
                      at org.jboss.kernel.plugins.dependency.ConfigureAction.dispatchSetProperty(ConfigureAction.java:107)
                      ... 49 more
              
              
              • 4. Re: JMS, Spring and Snowdrop. Listening for an injection of bean factory to JNDI
                Marius Bogoevici Expert

                As far as I know, the default relativeOrder of deployers is Integer.MAX_VALUE, and negative values have no special meaning (except that they're much lower than others).

                 

                Setting the value to -1 should be safe, because the Spring deployers do not depend on other deployers (in the same phase).

                 

                In any case, please follow https://issues.jboss.org/browse/SNOWDROP-26

                 

                A Snowdrop 2.0.0.M2 release is forthcoming and I would like to capture this issue there.

                • 5. Re: JMS, Spring and Snowdrop. Listening for an injection of bean factory to JNDI
                  Michal Szynkiewicz Newbie

                  Thank you for all your help

                   

                  When is 2.0 planned to be released?