9 Replies Latest reply on Sep 22, 2010 2:43 PM by marius.bogoevici

    Deployer problem: Duplicate ApplicationContext & Beans created

    myddryn

      I am having a a problem with the spring deployer creating duplicate instances of a spring program from *-spring.xml files in the deploy directory.  It appears as though the xml file gets read and parsed once, and the the ApplicationContext and all beans in the xml file get created TWICE.

       

      I have no idea where to start with this problem.  I have verified that there aren't any redundant spring jars in the classpath.  Any pointers would be greatly appreciated.

       

      I am using:

       

      jboss 5.1.0

      spring 3.0.3

      spring deployer 3.3 from snowdrop (same problem with spring-int from jboss svn)

        • 1. Re: Deployer problem: Duplicate ApplicationContext & Beans created
          alesj

          What's your app file structure?

           

          Or perhaps turn on the debug/trace log, and check where the duplicate comes from.

          (hopefully our deployers have decent logging )

          • 2. Re: Deployer problem: Duplicate ApplicationContext & Beans created
            myddryn

            There is no app, it is just a spring xml file placed directly in the deploy directory which is instantiating beans.  That all works fine, its just the duplication that is an issue.

             

            Turning on tracing overall produces huge logs.  Can you suggest a particular category or set of classes to trace?

            • 3. Re: Deployer problem: Duplicate ApplicationContext & Beans created
              alesj
              Turning on tracing overall produces huge logs.  Can you suggest a particular category or set of classes to trace?

              From the deployers package name:

              * http://anonsvn.jboss.org/repos/jbossas/projects/snowdrop/trunk/deployers/src/main/java/org/jboss/spring/deployers/

              looks like you should filter "org.jboss.spring" -- probably can also add ".deployer" for more detailed log.

               

              Or perhaps you could debug this few deployers, and potentially see why it gets called twice?

               

              I'll do a quick check asap, trying to understand why it would trigger twice.

              • 4. Re: Deployer problem: Duplicate ApplicationContext & Beans created
                myddryn

                Here is a trace of the spring deployer.  This is done in a very simple setup.  The only things in the 'deploy' directory are "hdscanner-jboss-beans.xml" (which is part of the jboss distribution) and "host-messenger-spring.xml" (which is the spring file seeing double deployment).

                 

                Let me know if you want more stuff logged.

                 

                2010-09-22 10:44:47,932 TRACE [org.jboss.spring.deployers.SpringParserDeployer] (main) Deploying: vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/hdscanner-jboss-beans.xml
                2010-09-22 10:44:47,932 TRACE [org.jboss.spring.deployers.SpringParserDeployer] (main) Deploying: vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/hdscanner-jboss-beans.xml
                2010-09-22 10:44:47,932 TRACE [org.jboss.spring.deployers.SpringParserDeployer] (main) Deployed:  vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/hdscanner-jboss-beans.xml
                2010-09-22 10:44:47,932 TRACE [org.jboss.spring.deployers.SpringParserDeployer] (main) Deployed:  vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/hdscanner-jboss-beans.xml
                2010-09-22 10:44:47,932 TRACE [org.jboss.spring.deployers.SpringParserDeployer] (main) Deploying: vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/host-messenger-spring.xml
                2010-09-22 10:44:47,932 TRACE [org.jboss.spring.deployers.SpringParserDeployer] (main) Deploying: vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/host-messenger-spring.xml
                2010-09-22 10:44:47,934 TRACE [org.jboss.spring.deployers.SpringParserDeployer] (main) Deployed:  vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/host-messenger-spring.xml
                2010-09-22 10:44:47,934 TRACE [org.jboss.spring.deployers.SpringParserDeployer] (main) Deployed:  vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/host-messenger-spring.xml
                2010-09-22 10:44:47,988 TRACE [org.jboss.spring.deployers.ApplicationContextDeployer] (main) Deploying: vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/host-messenger-spring.xml
                2010-09-22 10:44:47,988 TRACE [org.jboss.spring.deployers.ApplicationContextDeployer] (main) Deploying: vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/host-messenger-spring.xml
                2010-09-22 10:44:48,073 INFO  [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Refreshing org.jboss.spring.factory.NamedXmlApplicationContext@42bc5245: startup date [Wed Sep 22 10:44:48 PDT 2010]; root of context h
                ierarchy
                2010-09-22 10:44:48,073 INFO  [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Refreshing org.jboss.spring.factory.NamedXmlApplicationContext@42bc5245: startup date [Wed Sep 22 10:44:48 PDT 2010]; root of context h
                ierarchy
                2010-09-22 10:44:48,221 INFO  [org.jboss.spring.factory.NamedXmlBeanDefinitionReader] (main) Loading XML bean definitions from URL [vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/host-messenger-spring.xml]
                2010-09-22 10:44:48,221 INFO  [org.jboss.spring.factory.NamedXmlBeanDefinitionReader] (main) Loading XML bean definitions from URL [vfsfile:/home/myddryn/runtime/jboss/server/amq/deploy/host-messenger-spring.xml]
                2010-09-22 10:44:48,664 DEBUG [org.jboss.spring.factory.NamedXmlBeanDefinitionParser] (main) Loading bean definitions
                2010-09-22 10:44:48,664 DEBUG [org.jboss.spring.factory.NamedXmlBeanDefinitionParser] (main) Loading bean definitions
                2010-09-22 10:44:48,905 INFO  [org.apache.camel.spring.handler.CamelNamespaceHandler] (main) camel-osgi.jar/camel-spring-osgi.jar not detected in classpath
                2010-09-22 10:44:48,905 INFO  [org.apache.camel.spring.handler.CamelNamespaceHandler] (main) camel-osgi.jar/camel-spring-osgi.jar not detected in classpath
                2010-09-22 10:44:50,118 DEBUG [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Bean factory for org.jboss.spring.factory.NamedXmlApplicationContext@42bc5245: org.springframework.beans.factory.support.DefaultListabl
                eBeanFactory@6bfcc7a9: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,template,consumerTemplate,camel:beanPostProcessor,camel,activemq,host-messenger,PrettyJSON]; root of factory hiera
                rchy
                2010-09-22 10:44:50,118 DEBUG [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Bean factory for org.jboss.spring.factory.NamedXmlApplicationContext@42bc5245: org.springframework.beans.factory.support.DefaultListabl
                eBeanFactory@6bfcc7a9: defining beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,template,consumerTemplate,camel:beanPostProcessor,camel,activemq,host-messenger,PrettyJSON]; root of factory hiera
                rchy
                2010-09-22 10:44:50,239 INFO  [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] (main) Loading properties file from URL [file:/home/myddryn/runtime/jboss/server/amq//conf/host_messenger.properties]
                2010-09-22 10:44:50,240 INFO  [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer] (main) Loading properties file from URL [file:/home/myddryn/runtime/jboss/server/amq//conf/activemq.properties]
                2010-09-22 10:44:50,256 DEBUG [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@3a
                a9f827]
                2010-09-22 10:44:50,256 DEBUG [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@3a
                a9f827]
                2010-09-22 10:44:50,260 DEBUG [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.
                SimpleApplicationEventMulticaster@550dcd3]
                2010-09-22 10:44:50,260 DEBUG [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.
                SimpleApplicationEventMulticaster@550dcd3]
                2010-09-22 10:44:50,260 INFO  [org.springframework.beans.factory.support.DefaultListableBeanFactory] (main) Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@6bfcc7a9: definin
                g beans [org.springframework.beans.factory.config.PropertyPlaceholderConfigurer#0,template,consumerTemplate,camel:beanPostProcessor,camel,activemq,host-messenger,PrettyJSON]; root of factory hierarchy

                 

                At this point logs from the host-messenger-spring.xml beans show duplicate instantiation.

                 

                Followed by:

                 

                2010-09-22 10:44:50,633 DEBUG [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycle
                Processor@1a46a171]
                2010-09-22 10:44:50,633 DEBUG [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycle
                Processor@1a46a171]
                2010-09-22 10:44:50,634 TRACE [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Publishing event in org.jboss.spring.factory.NamedXmlApplicationContext@42bc5245: org.springframework.context.event.ContextRefreshedEve
                nt[source=org.jboss.spring.factory.NamedXmlApplicationContext@42bc5245: startup date [Wed Sep 22 10:44:48 PDT 2010]; root of context hierarchy]
                2010-09-22 10:44:50,634 TRACE [org.jboss.spring.factory.NamedXmlApplicationContext] (main) Publishing event in org.jboss.spring.factory.NamedXmlApplicationContext@42bc5245: org.springframework.context.event.ContextRefreshedEve
                nt[source=org.jboss.spring.factory.NamedXmlApplicationContext@42bc5245: startup date [Wed Sep 22 10:44:48 PDT 2010]; root of context hierarchy]

                 

                Followed by more messages from the beans showing duplicate instantiation.

                • 5. Re: Deployer problem: Duplicate ApplicationContext & Beans created
                  marius.bogoevici

                  Adam,

                   

                  Do you actually see two different instances, or is that something you infer from the logs. Because the way I read the log seems to indicate that there is a single NamedXmlApplicationContext instance, but the trace messages are duplicated? i.e. the instantiate/refresh messages show up twice indeed, but they refer to the same instance?

                  • 6. Re: Deployer problem: Duplicate ApplicationContext & Beans created
                    myddryn

                    Marius Bogoevici wrote:

                     

                    Adam,

                     

                    Do you actually see two different instances, or is that something you infer from the logs. Because the way I read the log seems to indicate that there is a single NamedXmlApplicationContext instance, but the trace messages are duplicated? i.e. the instantiate/refresh messages show up twice indeed, but they refer to the same instance?

                     

                    I can tell that there are two different instances because one of the things the beans do on startup is make some SOAP type calls out to another server and I can see the double hit in that remote server's logs.

                     

                    I have run this exact same set of beans and spring xml under another app server (not jboss) without modification and not seen the double hit.

                    • 7. Re: Deployer problem: Duplicate ApplicationContext & Beans created
                      myddryn

                      Now I have to take that back.  I just ran the test again and only see one hit on the remote server.

                       

                      Curiouser and curiouser.  I only see double log entries for the spring applications.  Why would that be?

                      • 8. Re: Deployer problem: Duplicate ApplicationContext & Beans created
                        myddryn

                        Seems to be some kind of logging setup issue.  Sorry to waste your time.

                         

                        -adam

                        • 9. Re: Deployer problem: Duplicate ApplicationContext & Beans created
                          marius.bogoevici

                          Not wasted .  Thanks for using Snowdrop.