Top Description Fields Constructors Methods
org.springframework.instrument.classloading

public Class SimpleInstrumentableClassLoader

extends OverridingClassLoader
Class Inheritance
Imports
java.lang.instrument.ClassFileTransformer, org.springframework.core.OverridingClassLoader, org.springframework.lang.Nullable

Simplistic implementation of an instrumentable ClassLoader.

Usable in tests and standalone environments.

Authors
Rod Johnson, Costin Leau
Since
2.0

Field Summary

Modifier and TypeField and Description
private final WeavingTransformer
Inherited from org.springframework.core.OverridingClassLoader:
DEFAULT_EXCLUDED_PACKAGES

Constructor Summary

AccessConstructor and Description
public
SimpleInstrumentableClassLoader(ClassLoader
the ClassLoader to build an instrumentable ClassLoader for
parent
)

Create a new SimpleInstrumentableClassLoader for the given ClassLoader.

Method Summary

Modifier and TypeMethod and Description
public void
addTransformer(ClassFileTransformer
the ClassFileTransformer to register
transformer
)

Add a ClassFileTransformer to be applied by this ClassLoader.

protected byte[]
transformIfNecessary(String
the fully-qualified name of the class being transformed
name
,
byte[]
the raw bytes of the class
bytes
)

Overrides org.springframework.core.OverridingClassLoader.transformIfNecessary.

Transformation hook to be implemented by subclasses.

Inherited from org.springframework.core.OverridingClassLoader:
isEligibleForOverridingloadBytesForClassloadClassloadClassloadClassForOverridingopenStreamForClass

Field Detail

weavingTransformerback to summary
private final WeavingTransformer weavingTransformer

Constructor Detail

SimpleInstrumentableClassLoaderback to summary
public SimpleInstrumentableClassLoader(ClassLoader parent)

Create a new SimpleInstrumentableClassLoader for the given ClassLoader.

Parameters
parent:ClassLoader

the ClassLoader to build an instrumentable ClassLoader for

Method Detail

addTransformerback to summary
public void addTransformer(ClassFileTransformer transformer)

Add a ClassFileTransformer to be applied by this ClassLoader.

Parameters
transformer:ClassFileTransformer

the ClassFileTransformer to register

transformIfNecessaryback to summary
protected byte[] transformIfNecessary(String name, byte[] bytes)

Overrides org.springframework.core.OverridingClassLoader.transformIfNecessary.

Doc from org.springframework.core.OverridingClassLoader.transformIfNecessary.

Transformation hook to be implemented by subclasses.

The default implementation simply returns the given bytes as-is.

Parameters
name:String

the fully-qualified name of the class being transformed

bytes:byte[]

the raw bytes of the class

Returns:byte[]

the transformed bytes (never null; same as the input bytes if the transformation produced no changes)

Annotations
@Override