title: How to make Tomcat work with TomcatInstrumentableClassLoader defined in META-INF/context.xml together with WEB-INF/lib/spring-instrument-tomcat.jar
body: <p>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  </p>
  
  <pre><code>&lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"/&gt;
  </code></pre>
  
  <p>If I put <code>spring-instrument-tomcat.jar</code> into <code>$TOMCAT_HOME/lib</code> then Tomcat runs mywebapp well but if I put <code>spring-instrument-tomcat.jar</code> into the <code>$TOMCAT_HOME/webapps/mywebapp/WEB-INF/lib</code> - Tomcat dies with exception  </p>
  
  <pre><code>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
  </code></pre>
  
  <p>Context loader parameter <code>useSystemClassLoaderAsParent</code> set to <code>false</code> does not help either.  </p>
  
  <p>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?</p>