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

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

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

If I put spring-instrument-tomcat.jarin $TOMCAT_HOME/lib, then Tomcat will do mywebapp well, but if I put spring-instrument-tomcat.jarin $TOMCAT_HOME/webapps/mywebapp/WEB-INF/lib- Tomcat dies with the 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 agent: -javaagent:org.springframework.instrument.jar

The context loader setting useSystemClassLoaderAsParentset to falsedoes not help either.

I don’t want to have a (custom) global library in Tomcat (and it will not be easy to have a global one in our real production system), so I'm trying to localize all the necessary things in a simple (but large) war file. Any thoughts on how to achieve this encapsulation?

+5
source share
2 answers

Well, if you don’t need additional jars in the Tomcat lib folder, the only option (there is still Spring / AspectJ LTW work) is to edit the tomcat script run to add -javaagent: ... tool.jar to its JAVA_OPTS or CATALINA_OPTS and delete context.xml file (you will no longer need TomcatInstrumentableClassLoad er).

+5
source

Maybe yours is context.xmlwrong. Try the following:

<?xml version="1.0" encoding="UTF-8" ?>
<Context>
  <Loader
    loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
    useSystemClassLoaderAsParent="false" />
</Context>
0

All Articles