Announcement Announcement Module
Collapse
No announcement yet.
Spring 2.5.5 - root WebApplicationContext intializes twice via ContextLoader Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring 2.5.5 - root WebApplicationContext intializes twice via ContextLoader

    I can't figure out why my root application context is loaded twice?

    This occurs even with an empty applicationContext.xml.
    If I define singleton beans, they are loaded twice.

    Here is the output from tomcat:
    Code:
    Oct 20, 2008 3:07:03 PM org.apache.tomcat.util.digester.SetPropertiesRule begin
    WARNING: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:ConsumerClient' did not find a matching property.
    Oct 20, 2008 3:07:03 PM org.apache.catalina.core.AprLifecycleListener init
    INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\usr\java\eclipse\jre\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:/usr/java/eclipse/jre/bin/../jre/bin/client;C:/usr/java/eclipse/jre/bin/../jre/bin;C:\usr\java\jdk1.6.0_07\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\OpenAFS\Client\Program;C:\Program Files\OpenAFS\Common;C:\usr\cygwin\bin;C:\usr\java\apache-ant-1.7.0\bin;C:\usr\java\axis-1.4\bin;C:\usr\java\apache-maven-2.0.9\bin;C:\Program Files\TortoiseSVN\bin;C:\Program Files\QuickTime\QTSystem\;C:\usr\java\jwsdp-2.0\jwsdp-shared\bin;C:\Program Files\CVSNT\
    Oct 20, 2008 3:07:03 PM org.apache.coyote.http11.Http11Protocol init
    INFO: Initializing Coyote HTTP/1.1 on http-8082
    Oct 20, 2008 3:07:04 PM org.apache.coyote.http11.Http11Protocol init
    INFO: Initializing Coyote HTTP/1.1 on http-8445
    Oct 20, 2008 3:07:04 PM org.apache.catalina.startup.Catalina load
    INFO: Initialization processed in 702 ms
    Oct 20, 2008 3:07:04 PM org.apache.catalina.core.StandardService start
    INFO: Starting service Catalina
    Oct 20, 2008 3:07:04 PM org.apache.catalina.core.StandardEngine start
    INFO: Starting Servlet Engine: Apache Tomcat/6.0.18
    Oct 20, 2008 3:07:04 PM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring root WebApplicationContext
    log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    log4j:WARN Please initialize the log4j system properly.
    Oct 20, 2008 3:07:05 PM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring root WebApplicationContext
    log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    log4j:WARN Please initialize the log4j system properly.
    Oct 20, 2008 3:07:05 PM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-8082
    Oct 20, 2008 3:07:05 PM org.apache.coyote.http11.Http11Protocol start
    INFO: Starting Coyote HTTP/1.1 on http-8445
    Oct 20, 2008 3:07:05 PM org.apache.jk.common.ChannelSocket init
    INFO: JK: ajp13 listening on /0.0.0.0:8010
    Oct 20, 2008 3:07:05 PM org.apache.jk.server.JkMain start
    INFO: Jk running ID=0 time=0/25  config=null
    Oct 20, 2008 3:07:05 PM org.apache.catalina.startup.Catalina start
    INFO: Server startup in 1815 ms
    NOTICE:
    Code:
    INFO: Initializing Spring root WebApplicationContext
    log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    log4j:WARN Please initialize the log4j system properly.
    Oct 20, 2008 3:07:05 PM org.apache.catalina.core.ApplicationContext log
    INFO: Initializing Spring root WebApplicationContext
    log4j:WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
    log4j:WARN Please initialize the log4j system properly.

  • #2
    My web.xml

    My web.xml
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
    	 xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
    	 id="client" version="2.5">
    	<display-name>Client</display-name>
    	<distributable/>
    	<context-param>
    		<param-name>log4jConfigLocation</param-name>
    		<param-value>classpath:com/mysite/client/log4j.properties</param-value>
    	</context-param>
    	<listener>
    		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    	</listener>
    	<welcome-file-list>
    		<welcome-file>index.html</welcome-file>
    		<welcome-file>index.htm</welcome-file>
    		<welcome-file>index.jsp</welcome-file>
    		<welcome-file>default.html</welcome-file>
    		<welcome-file>default.htm</welcome-file>
    		<welcome-file>default.jsp</welcome-file>
    	</welcome-file-list>
    	<error-page>
    		<error-code>500</error-code>
    		<location>/WEB-INF/jsp/ServerError.jsp</location>
    	</error-page>
    </web-app>

    Comment


    • #3
      my applicationContext.xml

      Notice it is EMPTY!

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans"
      	xmlns:p="http://www.springframework.org/schema/p"
      	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      	xmlns:aop="http://www.springframework.org/schema/aop"
      	xmlns:context="http://www.springframework.org/schema/context"
      	xmlns:jee="http://www.springframework.org/schema/jee"
      	xmlns:tx="http://www.springframework.org/schema/tx"
      	xmlns:util="http://www.springframework.org/schema/util"
      	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
      		http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
      		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
      		http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
      		http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
      		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
      </beans>

      Comment


      • #4
        Are you sure that it's not just logged twice but initialized only once?

        Comment


        • #5
          not being logged twice

          Yes, I am positive. If I define a bean that displays the time upon initialization, it prints out two different times.

          Could this be a bug in 2.5.5?

          Comment


          • #6
            look you tomcat->conf->server.xml
            Hava you deployed you application twice?

            Comment


            • #7
              bizarre

              bizarre!

              That was it. I was deploying tomcat under Eclipse 3.4 which generates all the config files automatically. There was only one reference in the server.xml it was generating, but I commented it out and everything loaded once. It apparently doesn't need that reference.

              I guess this is another bug in eclipse!

              Thanks!

              Comment


              • #8
                Another possible cause

                I came to this thread with a similar symptom, which I solved on my own, and wanted to share the answer in case it can help someone else.

                I found two instances of (apparent) double initialization:
                1. Adding a Spring listener when it is not needed. I am using Spring MVC as a servlet in Jetty, and also had a Spring ContextLoaderListener configured in web.xml, which caused double initialization of the whole Spring stack.
                2. Using autowiring with classes instead of interfaces. For my particular case, I was logging a message in the class constructor and these messages showed up twice on the log. The reason for this is that Spring is creating on the fly a proxy object that inherits from the class, so there are actually two distinct objects logging the message. This can be checked by logging a message such as log("Creating foo: " + this). This is another reason why you should always prefer to autowire based on interfaces.

                Hope this helps. Best regards.

                Comment

                Working...
                X