Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Tomcat work with TomcatInstrumentableClassLoader defined in META-INF/context.xml together with WEB-INF/lib/spring-instrument-tomcat.jar

I'd built a simple app which uses Spring Data 3.1.0.RELEASE and Eclipselink 2.4 on the server side - which is hosted in the Tomcat 7.0.27. In mywebapp/META-INF/context.xml I have Spring classloader

<Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/>

If I put spring-instrument-tomcat.jar into $TOMCAT_HOME/lib then Tomcat runs mywebapp well but if I put spring-instrument-tomcat.jar into the $TOMCAT_HOME/webapps/mywebapp/WEB-INF/lib - Tomcat dies with exception

java.lang.IllegalStateException: ClassLoader [org.apache.catalina.loader.WebappClassLoader] does NOT provide an 'addTransformer(ClassFileTransformer)' method. Specify a custom LoadTimeWeaver or start your Java virtual machine with Spring's agent: -javaagent:org.springframework.instrument.jar

Context loader parameter useSystemClassLoaderAsParent set to false does not help either.

I don't want to have any (custom) global lib in Tomcat (and it won't be easy to have the global one in our real-life production system) thus I'm trying to localize all the needed stuff in simple (yet big) war file. Any thoughts on how to achieve such encapsulation?

like image 745
aka_sh Avatar asked Jun 28 '12 14:06

aka_sh


1 Answers

Well, if you do not want extra jars in Tomcat's lib folder, the only option (to still have Spring / AspectJ LTW work) is to edit the tomcat's run script to add -javaagent:...instrument.jar to its JAVA_OPTS or CATALINA_OPTS, and remove the context.xml file (you won't need TomcatInstrumentableClassLoad‌​er anymore).

like image 174
rodche Avatar answered Oct 11 '22 17:10

rodche