Results 1 to 10 of 10

Thread: Need to Regain My Sanity - Contexts Loading Twice

Hybrid View

  1. #1
    Join Date
    Sep 2005
    Location
    West Bloomfield, MI
    Posts
    32

    Default Need to Regain My Sanity - Contexts Loading Twice

    I have a web application shell running on Tomcat. It's based on an architecture I set up -- and all of my applications have the same problem, even this shell: when the app starts up, I see all of my contexts loaded *twice*. I know this is a common problem, but I can't seem to figure it out!

    If I remove the listener and its associated context param, the dispatch loads player-servlet once, but it doesn't load commonContext.xml doesn't load (and I wouldn't expect it to, either).

    Help an old man get his sanity back... :-)

    web.xml snippets:
    Code:
        <servlet>
            <servlet-name>player</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
    
        <servlet-mapping>
            <servlet-name>player</servlet-name>
            <url-pattern>/app/*</url-pattern>
        </servlet-mapping>
    
        <context-param>
          <param-name>contextConfigLocation</param-name>
          <param-value>/WEB-INF/commonContext.xml</param-value>
        </context-param>
    
        <listener>
          <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
    commonContext.xml:
    Code:
        <bean id="messageSource" class="org.springframework.context.support.ResourceBundleMessageSource">
            <property name="basename">
                <value>messages</value>
            </property>
        </bean>
        
        <import resource="dao.xml"/>
        <import resource="services.xml"/>                           
        <import resource="constants.xml"/>
    dao.xml:
    Code:
        <import resource="conf/mysql/dao.xml"/>

    conf/mysql/dao.xml:
    Code:
        <bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/>
    
        <bean id="chdbPoolAdapter" class="org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS">    
            <property name="driver" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/chdb?autoReconnect=true"/>
            <property name="user" value="root"/>
            <property name="password" value=""/>
        </bean>
        
        <bean id="chdbDataSource" class="org.apache.commons.dbcp.datasources.SharedPoolDataSource">
            <property name="connectionPoolDataSource" ref="chdbPoolAdapter"/>
            <property name="maxActive" value="100"/>
            <property name="maxIdle" value="30"/>
            <property name="maxWait" value="10000"/>
        </bean>        
        
        <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
              <property name="dataSource" ref="chdbDataSource"/>
        </bean>
    
        <bean id="txInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor">
              <property name="transactionManager" ref="txManager"/>
              <property name="transactionAttributeSource">
                <bean class="org.springframework.transaction.annotation.AnnotationTransactionAttributeSource"/>
              </property>
        </bean>                        
    
        <bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
              <property name="transactionInterceptor" ref="txInterceptor"/>
        </bean>
    services.xml:
    (empty)

    constants.xml:
    (empty)

    player-servlet.xml:
    Code:
        <bean id="urlPathController" class="com.xyzcompany.spring.controllers.UrlPathViewController"/>
               
        <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property>
            <property name="prefix"><value>/WEB-INF/views/</value></property>
            <property name="suffix"><value>.jsp</value></property>
        </bean>    
            
        <bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
            <property name="urlMap">
                <map>
                     <entry key="/*.view" value-ref="urlPathController"/>
                </map>
            </property>
        </bean>

  2. #2
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    Is the player-servlet.xml displayed here the full context? Make sure youi don't import a xml file twice (that is just why I almost never use imports).

    Also make sure that none of your own classes create a new ApplicationContext.
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

  3. #3
    Join Date
    Sep 2005
    Location
    West Bloomfield, MI
    Posts
    32

    Default

    Yes, it is the full context. I am not explicitly creating any application contexts anywhere in my code -- in fact, I don't really even HAVE any code. This is a shell....

    I like the import functionality because it makes for very nice separation and a significantly easier to configure application. In my humble opinion, at least.

    Unless it causes double context loads... in which case, I'll drop it

    Dan
    Last edited by dantelope; Feb 12th, 2007 at 12:48 PM.

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Just out of interested how do you know it's loading twice? If you can see it in the logs, could we see the logs?

  5. #5
    Join Date
    Sep 2005
    Location
    West Bloomfield, MI
    Posts
    32

    Default

    I reason that it's loading twice because I see the same series of of context loads twice... maybe I'm just in need of a new prescription for my glasses?

    Text log file attached.
    Attached Files Attached Files

  6. #6
    Join Date
    Jun 2006
    Location
    The Netherlands
    Posts
    13,625

    Default

    I like the import functionality because it makes for very nice separation and a significantly easier to configure application. In my humble opinion, at least.
    You can have that without the import functionality. Just include/specify all your configuration files on the ConfigLocation path. Which is imho even greater because your config files don't even have to know about each other (as you do with the import function).

    Code:
    <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>
            /WEB-INF/commonContext.xml
            /WEB-INF/dao.xml
            /WEB-INF/services.xml
            /WEB-INF/constants.xml
       </param-value>
    </context-param>
    Will result in the same.

    However that wasn't your question

    From your logfile it appears, indeed, that the context loads twice, at least that is what it looks like. The weird thing is it also appears that your servlet is being initialized twice.

    Is your application somehow being loaded twice?
    Marten Deinum
    Java Consultant / Pragmatist / Open Source Enthousiast / Author


    Pro Spring MVC: With Web Flow
    Conspect

    Have you read the reference guide.
    Use the [ code ] tags, young padawan

Posting Permissions

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