• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

WebSphere J2EE Module Dependencies

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have an EAR file which contains 4 webapps. The jars used by each webapp reside at the EAR level. Now each webapp references these jars as J2EE modules under Properties>J2EE Module Dependencies>J2EE Modules. This causes a problem in my application which uses spring. Each webapp seems to use the same spring context which cause problems when beans with the same name are created by each webapp. Is this the correct behavior? When you reference jars as J2EE Modules does it lead to a share context across all web apps?

Thanks in advance
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This problem could be caused by using a Singleton Spring bean factory. Because all of your web applications share the same JVM, they'll also share the same bean factory. I'd suggest you switch to a bean factory stored in the ServletContext object. That way you're sure to have a separate one for each web application.

Another possibility would be to configure WAS such that each web application has its own ClassLoader.
 
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ah....WebSphere classloading issues... I have a little tutorial on the topic that you might find useful:

WebSphere Classloading - Understanding how classes get loaded onto the JVM in WebSphere

Indeed, with all of the war files pulling from common jar files in the root of the ear, they will all be accessing the Spring resources through the same classloader.

These are the WebSphere classloaders:


Everything is probably being loaded by the common CompoundClassLoader, which is causing the problems.

Using the ServletContext is a good idea. What if you package the Spring components in the lib directory of the war files? Alternatively, you might want to switch around the PARENT_FIRST and PARENT_LAST settings on the web module.

Good luck! Classloader issues are always a pain.

-Cameron McKenzie
 
Pat Short
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the quick response everyone. Each web app in the EAR is configured to have its own classloader. This option is selected under Enterprise Applications>MYEAR>Class loader. Also, the spring context is tied to the servletcontext as suggested below.

I've found a solution to the problem in the way I reference my jars in each web application. In my original thread, I posted that each webapp references these EAR level jars as J2EE modules under Properties>J2EE Module Dependencies>J2EE Modules in RAD. However, if I reference the jars as "Web Libraries" instead of "J2EE Modules" under the same configuraton option in my RAD environment, the problem does not occur. By changing this configuration option, each webapp get a copy of the jar files in their WEB-INF/lib directory. This solves my problems.

Therefore, this suggests if you want to share context among web apps in an EAR file, reference the EAR level jars as J2EE Modules. However, if each web needs its own copy, then reference the jars as Web Libraries. Hope this makes sense. Let me know if there's anything strange with this configuration.

Thanks
 
Cameron Wallace McKenzie
author and cow tipper
Posts: 5009
1
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No problems with this at all. This is exactly how it should be done!

-Cameron McKenzie
 
moose poop looks like football shaped elk poop. About the size of this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic