Results 1 to 3 of 3

Thread: Singleton bean created twice?

  1. #1

    Default Singleton bean created twice?

    Hello!

    I experience a very strange behaviour at application startup, for which i do not find an explanation.
    I have a singleton bean defined in the application context:
    Code:
    <bean id="eventMulticaster" class="org.springframework.context.event.ApplicationEventMulticasterImpl"/>
    When i start my application, i get the following output (note that "Creating shared instance of singleton bean 'eventMulticaster' " appears twice).
    Code:
    ...
    Loading XML bean definitions from resource &#91;/WEB-INF/bwz-servlet.xml&#93; of ServletContext 
    2004-09-06 15&#58;50&#58;56,872 INFO &#91;org.springframework.beans.factory.xml.XmlBeanDefinitionReader&#93; 
     Loading XML bean definitions from resource &#91;/WEB-INF/bwz-security.xml&#93; of ServletContext 
    2004-09-06 15&#58;50&#58;57,193 INFO &#91;org.springframework.beans.factory.xml.XmlBeanDefinitionReader&#93; 
     Loading XML bean definitions from resource &#91;/WEB-INF/bwz-db-hibernate.xml&#93; of ServletContext 
    2004-09-06 15&#58;50&#58;57,332 INFO &#91;org.springframework.web.context.support.XmlWebApplicationContext&#93; 
     Bean factory for application context &#91;Root XmlWebApplicationContext&#93;&#58; org.springframework.beans.factory.support.DefaultListableBeanFactory defining beans &#91;&#40;...&#41;&#93;; Root of BeanFactory hierarchy 
    2004-09-06 15&#58;50&#58;57,362 INFO &#91;org.springframework.web.context.support.XmlWebApplicationContext&#93; 
     58 beans defined in ApplicationContext &#91;Root XmlWebApplicationContext&#93; 
    ...
    2004-09-06 15&#58;50&#58;57,624 INFO &#91;org.springframework.beans.factory.support.DefaultListableBeanFactory&#93; 
     Creating shared instance of singleton bean 'eventMulticaster' 
    ...
     Published root WebApplicationContext &#91;org.springframework.web.context.support.XmlWebApplicationContext&#58; displayName=&#91;Root XmlWebApplicationContext&#93;; startup date=&#91;Mon Sep 06 15&#58;50&#58;55 CEST 2004&#93;; root of ApplicationContext hierarchy; config locations=&#91;/WEB-INF/bwz-servlet.xml,/WEB-INF/bwz-security.xml,/WEB-INF/bwz-db-hibernate.xml&#93;; &#93; as ServletContext attribute with name &#91;interface org.springframework.web.context.WebApplicationContext.ROOT&#93; 
    2004-09-06 15&#58;52&#58;38,355 INFO &#91;org.springframework.web.servlet.DispatcherServlet&#93; 
     Initializing servlet 'bwz' 
    2004-09-06 15&#58;52&#58;38,423 INFO &#91;org.springframework.web.servlet.DispatcherServlet&#93; 
     Framework servlet 'bwz' init 
    2004-09-06 15&#58;52&#58;38,424 INFO &#91;org.springframework.web.servlet.DispatcherServlet&#93; 
     Servlet with name 'bwz' will try to create custom WebApplicationContext context of class 'org.springframework.web.context.support.XmlWebApplicationContext' using parent context &#91;org.springframework.web.context.support.XmlWebApplicationContext&#58; displayName=&#91;Root XmlWebApplicationContext&#93;; startup date=&#91;Mon Sep 06 15&#58;50&#58;55 CEST 2004&#93;; root of ApplicationContext hierarchy; config locations=&#91;/WEB-INF/bwz-servlet.xml,/WEB-INF/bwz-security.xml,/WEB-INF/bwz-db-hibernate.xml&#93;; &#93; 
    ...
    2004-09-06 15&#58;56&#58;24,735 INFO &#91;org.springframework.beans.factory.support.DefaultListableBeanFactory&#93; 
     Creating shared instance of singleton bean 'eventMulticaster'
    I do not know why this bean is created twice, and why some of my classes get bean 1 and others bean 2.
    I saw the lines which say that a context for servlet bwz with the root context as parent is constructed. But i do not know what this means... i only have one servlet with application contexts and do not try to build up parent-child-contexts (at least not to my knowledge...!).

    Does somebody have an idea? I am a bit lost after searching around for three hours...

    Thanks a lot!
    Sebastian

  2. #2
    Join Date
    Aug 2004
    Location
    Southampton, UK
    Posts
    826

    Default

    Can yuo post more of your code. Specifically can you post web.xml, the application context config for that bean in full and also any code you have that may create application contexts.

  3. #3

    Default

    Okay, i solved this problem today... just in case somebody else runs into the same situation: i was not aware that two contexts are created, one big "parent" application context and one servlet specific context.

    Unfortunately one of my config files was included in both contexts, and therfore certain beans were created twice. Events sent within one context did not reach beans in the other one.... this really took me a few hours to learn, but now it's working and i am happy again... ;-)

    Sebastian

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. EHCaching Hibernate
    By dencamel in forum Data
    Replies: 3
    Last Post: Sep 6th, 2005, 09:03 PM
  3. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  4. could not satisfy dependencies
    By springuser in forum Container
    Replies: 4
    Last Post: Apr 26th, 2005, 01:15 PM
  5. Replies: 1
    Last Post: Apr 25th, 2005, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •