org.springframework.instrument.classloading.tomcat
Class TomcatInstrumentableClassLoader

java.lang.Object
  extended by java.lang.ClassLoader
      extended by java.security.SecureClassLoader
          extended by java.net.URLClassLoader
              extended by org.apache.catalina.loader.WebappClassLoader
                  extended by org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader
All Implemented Interfaces:
org.apache.catalina.Lifecycle, org.apache.catalina.loader.Reloader

public class TomcatInstrumentableClassLoader
extends org.apache.catalina.loader.WebappClassLoader

Extension of Tomcat's default class loader which adds instrumentation to loaded classes without the need to use a VM-wide agent.

To be registered using a Loader tag in Tomcat's Context definition in the server.xml file, with the Spring-provided "spring-tomcat-weaver.jar" file deployed into Tomcat's "server/lib" directory. The required configuration tag looks as follows:

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

Typically used in combination with a ReflectiveLoadTimeWeaver defined in the Spring application context. The addTransformer and getThrowawayClassLoader methods mirror the corresponding methods in the LoadTimeWeaver interface, as expected by ReflectiveLoadTimeWeaver.

See the PetClinic sample application for a full example of this ClassLoader in action.

NOTE: Requires Apache Tomcat version 5.0 or higher.

Since:
2.0
Author:
Costin Leau, Juergen Hoeller
See Also:
addTransformer(java.lang.instrument.ClassFileTransformer), getThrowawayClassLoader(), ReflectiveLoadTimeWeaver

Nested Class Summary
 
Nested classes/interfaces inherited from class org.apache.catalina.loader.WebappClassLoader
org.apache.catalina.loader.WebappClassLoader.PrivilegedFindResource
 
Field Summary
 
Fields inherited from class org.apache.catalina.loader.WebappClassLoader
allPermission, delegate, files, hasExternalRepositories, jarFiles, jarNames, jarPath, jarRealFiles, lastJarAccessed, lastModifiedDates, loaderDir, loaderPC, log, needConvert, notFoundResources, packageTriggers, parent, paths, permissionList, repositories, repositoryURLs, resourceEntries, resources, securityManager, sm, started, system, triggers
 
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, DESTROY_EVENT, INIT_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
 
Constructor Summary
TomcatInstrumentableClassLoader()
          Create a new TomcatInstrumentableClassLoader using the current context class loader.
TomcatInstrumentableClassLoader(ClassLoader parent)
          Create a new TomcatInstrumentableClassLoader with the supplied class loader as parent.
 
Method Summary
 void addTransformer(ClassFileTransformer transformer)
          Delegate for LoadTimeWeaver's addTransformer method.
protected  org.apache.catalina.loader.ResourceEntry findResourceInternal(String name, String path)
           
 ClassLoader getThrowawayClassLoader()
          Delegate for LoadTimeWeaver's getThrowawayClassLoader method.
 String toString()
           
 
Methods inherited from class org.apache.catalina.loader.WebappClassLoader
addLifecycleListener, addPermission, addPermission, addPermission, addRepository, addURL, cleanElCache, clearReferences, closeJARs, deleteDir, filter, findClass, findClassInternal, findLifecycleListeners, findLoadedClass0, findLoadedResource, findRepositories, findResource, findResourceInternal, findResources, getAntiJARLocking, getDelegate, getJarPath, getPermissions, getResource, getResourceAsStream, getResources, getURI, getURL, getURLs, isPackageSealed, loadClass, loadClass, loadedByThisOrChild, modified, nullInstance, openJARs, refreshPolicy, removeLifecycleListener, setAntiJARLocking, setDelegate, setJarPath, setParentClassLoader, setResources, setWorkDir, start, stop, validate, validateJarFile
 
Methods inherited from class java.net.URLClassLoader
definePackage, newInstance, newInstance
 
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
 
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findLibrary, findLoadedClass, findSystemClass, getPackage, getPackages, getParent, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, resolveClass, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TomcatInstrumentableClassLoader

public TomcatInstrumentableClassLoader()
Create a new TomcatInstrumentableClassLoader using the current context class loader.

See Also:
TomcatInstrumentableClassLoader(ClassLoader)

TomcatInstrumentableClassLoader

public TomcatInstrumentableClassLoader(ClassLoader parent)
Create a new TomcatInstrumentableClassLoader with the supplied class loader as parent.

Parameters:
parent - the parent ClassLoader to be used
Method Detail

addTransformer

public void addTransformer(ClassFileTransformer transformer)
Delegate for LoadTimeWeaver's addTransformer method. Typically called through ReflectiveLoadTimeWeaver.

See Also:
LoadTimeWeaver.addTransformer(java.lang.instrument.ClassFileTransformer), ReflectiveLoadTimeWeaver

getThrowawayClassLoader

public ClassLoader getThrowawayClassLoader()
Delegate for LoadTimeWeaver's getThrowawayClassLoader method. Typically called through ReflectiveLoadTimeWeaver.

See Also:
LoadTimeWeaver.getThrowawayClassLoader(), ReflectiveLoadTimeWeaver

findResourceInternal

protected org.apache.catalina.loader.ResourceEntry findResourceInternal(String name,
                                                                        String path)
Overrides:
findResourceInternal in class org.apache.catalina.loader.WebappClassLoader

toString

public String toString()
Overrides:
toString in class org.apache.catalina.loader.WebappClassLoader


Copyright © 2002-2008 The Spring Framework.