java - multiple Spring root WebApplicationContexts -


i have tomcat server 2 webapps (foo , bar) have identical deployment war. deployment uses standard spring/hibernate setup. assumed these 2 webapps start , run independent of 1 another, not case - webapp foo loads normally, webapp bar has strange behavior - it's if using of same beans webapp foo. example, when bar starts (the 2nd webapp start), c3p0 complains registered - presumably in webapp foo. again, i'm trying make 2 webapps independent, such there should no way 2 c3p0/hibernatesessionfactory beans know 1 another.

in doing research, i've been led believe same spring root webapplicationcontext being used in both webapps. if case, how can make each webapp (on same tomcat server) independent of 1 another? there else causing problem?

relevant excerpts 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> 

i have suspision. isn't class-loading root of problem?

i guess direct reason problem spring class loaded once , shared between these 2 wars. don't know exact name of class, spring needs store shared information (at least reference application context) in static field. when 2 wars see same copy of class, both applications see same state of static field. guess in setup spring creates 1 application context (when second 1 should created, spring finds existing application context , uses instead).

i see potential 2 reasons such problem:

  • either class-loading issue. not tomcat , have no clue how , if can configure that, typically in javaee application servers there's way configure class-loading wars.
  • or kind of memory leak. maybe class (and static field) re-used previous deployment (unlikely, description tends suggest encounter problem on fresh instance of tomcat). can rule out possibility making sure problem appears after (re)started tomcat.

update: if class-loading, try figure out class (and static field) causing problems. not class 3rd-party library class use in application. after reading http://tomcat.apache.org/tomcat-6.0-doc/class-loader-howto.html can see tomcat uses different unrelated class loaders each application. both of them share parent class loaders delegate if don't know class. again, don't know exact setup , tomcat peculiarities, but... isn't possible in tomcat put library (jar), c3p0 or spring, in common 'lib' folder (the docs says $catalina_home/lib)? in such case classes these jars loaded using parent class loader (the 1 called 'common' in tomcat docs). implies loaded once.

to make story short, guess reason 1 of jars in $catalina_home/lib has class relies heavily on static fields. tomcat policy load jars using common class loader results in applications sharing state of these static fields.

have told suspicion , guessing?


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -