Multiple Spring root WebApplicationContexts

I have a tomcat server with two webapps (foo and bar) that have an identical deployment war. The deployment uses the standard Spring / Hibernate installation. I assumed that these two webapps start and start completely independently of each other, but this is not so - webapp foo loads fine, but there is a strange behavior in the webapp panel - it is as if it used some of the same beans from webapp foo. For example, when a bar starts (the second webapp starts), c3p0 complains that it is already registered - presumably in webapp foo. Again, I'm trying to make two webapps completely independent, so there should be no way for the two c3p0 / hibernateSessionFactory beans to know about each other.

In some research, I was convinced that the same root WebApplicationContext Spring is used in both Webapps. If so, how can I make each webapp (on the same tomcat server) completely independent of each other? Is there anything else that might cause this problem?

Relevant excerpts from web.xml:

<web-app>
    <context-param>
        <param-name>org.hibernate.tags.sessionFactory</param-name>
        <param-value>hibernate/SessionFactory</param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name> 
        <param-value>/WEB-INF/context/*Context.xml</param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>fooServlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
</web-app>
+3
source share
1 answer

I have a suspicion. Does root root your problem?

, , Spring WAR. , Spring ( , ) - . , WARs , . , Spring ( , Spring ).

:

  • . tomcat , , , , JavaEE WAR.
  • . , ( ) (, , , , tomcat). , , , () tomcat.

UPDATE: , , ( ) . , , , - , . http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html , Tomcat . , , . , Tomcat, ... Tomcat (JAR), c3p0 Spring, "lib" ( docs $CATALINA_HOME/lib)? JAR (, "Common" tomcat). , .

, , , JAR $CATALINA_HOME/lib , . Tomcat JAR Common class loader , .

, ?

+1

Source: https://habr.com/ru/post/1778032/


All Articles