views:

222

answers:

1

I am currently developing a web application based upon Struts2 & Spring components combined with a set of tier libraries in a company-made framework.

These librairies expose sets of spring beans, through blahblah.xml files embedded in the provided jar files.

I need to replace some of the implementation classes exposed through such bean declarations with my own classes, in order to add extra stuff in the provided processing.

People who designed the company-made framework chose to expose the blahblah.xml files to Spring through a specific Listener & WebApplicationContext that defines such configLocations :

ConfigurableWebApplicationContext cwac = new XmlWebApplicationContext();
cwac.setConfigLocation("classpath*:<somePath>/blahblah.xml");

For the moment I see only one way to achieve the job (but maybe I'm wrong, please let me know !) : make a copy of blahblah.xml out of the jar in a fake directory structure, modify the implementation class of some beans inside the copy, and then put the folder that includes the fake structure in the webapp classpath in order to "shadow" the original one.

That is what leads me to the problem of being able to force precedence to this in the classpath of TOMCAT 5.5 that I use for development under eclipse 3.3.

Although I added the directory containing the fake structure in the Classpath tab of the Launch Configuration of my Tomcat Server under eclipse 3.3, the injected object is still the original one instead of mine. I guess that my folder is placed after the WEB-INF/lib jars in the TOMCAT running classpath, but I have no way to grab it.

Any ideas ?

+1  A: 

Tomcat's classloading precedence for webapps is roughly as follows: first the bootstrap/system (JRE/lib, then server.loader), then the webapp libraries (WEB-INF/classes, then WEB-INF/lib), then the common libraries (common.loader, then Tomcat/lib) and finally the webapp-shared libraries (shared.loader).

I would start by adding this file to WEB-INF/classes (in Eclipse: just drop file in the src folder, it will be automagically taken into account).

Note that you cannot control the classloading precedence without some heavy customized classloader. You just have to know the default classloading order and use it wisely.

BalusC
Wooow it works perfectly; putting my fake structure in src folder does the job ! Thank you very much.
zim2001
You're welcome.
BalusC