Announcement Announcement Module
Collapse
No announcement yet.
Spring application context is loaded twice Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring application context is loaded twice

    When I initialize spring application context, I noticed that its log input twoice for same message, I think it is loaded twice in one,

    private static final String SPRING_CONFIG_FILE[] =
    new String[]{"/spring-config-global.xml", "/spring-config-beans.xml", "/acegi-security.xml", "/acegi-authorities.xml"};
    private static ApplicationContext appContext = null;

    public static synchronized ApplicationContext getAppContext() {
    System.out.println("**************************Inia lidkdf");
    if (appContext == null) {
    appContext = new ClassPathXmlApplicationContext(SPRING_CONFIG_FILE) ;
    }
    return appContext;
    }

    The log output is:
    [2006-07-25 16:57:19,296] [org.springframework.core.CollectionFactory.<clinit >(CollectionFactory.java:66)] INFO JDK 1.4+ collections available
    [2006-07-25 16:57:19,296] [org.springframework.core.CollectionFactory.<clinit >(CollectionFactory.java:66)] INFO JDK 1.4+ collections available
    [2006-07-25 16:57:19,312] [org.springframework.core.CollectionFactory.<clinit >(CollectionFactory.java:71)] INFO Commons Collections 3.x available
    [2006-07-25 16:57:19,312] [org.springframework.core.CollectionFactory.<clinit >(CollectionFactory.java:71)] INFO Commons Collections 3.x available
    [2006-07-25 16:57:19,343] [org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:163)] INFO Loading XML bean definitions from class path resource [spring-config-global.xml]
    [2006-07-25 16:57:19,343] [org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:163)] INFO Loading XML bean definitions from class path resource [spring-config-global.xml]
    [2006-07-25 16:57:19,500] [org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:163)] INFO Loading XML bean definitions from class path resource [spring-config-beans.xml]
    [2006-07-25 16:57:19,500] [org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:163)] INFO Loading XML bean definitions from class path resource [spring-config-beans.xml]
    [2006-07-25 16:57:19,625] [org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:163)] INFO Loading XML bean definitions from class path resource [acegi-security.xml]
    [2006-07-25 16:57:19,625] [org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:163)] INFO Loading XML bean definitions from class path resource [acegi-security.xml]
    [2006-07-25 16:57:19,718] [org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:163)] INFO Loading XML bean definitions from class path resource [acegi-authorities.xml]
    [2006-07-25 16:57:19,718] [org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:163)] INFO Loading XML bean definitions from class path resource [acegi-authorities.xml]

    See each message is print twice.
    What's the problem?

  • #2
    Where are you configuring your applicationcontext? Where is the method getAppContext called I mean.

    Also why are you loading the context yourself? If it is a webapplication use the servlet or listener to initialize your applicationcontext. If you really need access to your applicationcontext, let your java class implement the ApplicationContextAware interface.

    Comment


    • #3
      Are you manually importing the xml file in another xml, i.e. does "spring-config-global.xml" manually import any of the other xml files?

      Comment


      • #4
        I didn't import any xml file. Only a properties file to be configured in that beans configuration.

        I write this as a Lookup service, it is invoked by backend or web layer source code when its needed.

        As this is application not web application, I don't want to put all my configuration in web-inf

        Comment


        • #5
          Can you send the listing of all of those xml files please.

          Comment


          • #6
            Since even static initializations are logged twice, I suspect that perhaps the logging configuration is not correct. To verify single/double instantiation I suggest to set breakpoints and debug into initialization to see if happens once or twice.

            Regards,
            Andreas

            Comment


            • #7
              I find the problem.
              It is due to log4j configuration additivity
              I set it to true, so its loggedd twice

              Comment

              Working...
              X