Package org.springframework.instrument.classloading

# Class ShadowingClassLoader

java.lang.Object
java.lang.ClassLoader
org.springframework.core.DecoratingClassLoader
org.springframework.instrument.classloading.ShadowingClassLoader

Direct Known Subclasses:
  `ResourceOverridingShadowingClassLoader`

public class ShadowingClassLoader extends org.springframework.core.DecoratingClassLoader
ClassLoader decorator that shadows an enclosing ClassLoader, applying registered transformers to all affected classes.

Since:
  2.0
Author:
  Rob Harrop, Juergen Hoeller, Costin Leau
See Also:
  - `addTransformer(java.lang.instrument.ClassFileTransformer)`
  - `OverridingClassLoader`

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String[]`
`DEFAULT_EXCLUDED_PACKAGES`
Packages that are excluded by default.

## Constructor Summary

Constructors
Constructor
Description
`ShadowingClassLoader(ClassLoader enclosingClassLoader)`
Create a new ShadowingClassLoader, decorating the given ClassLoader, applying `DEFAULT_EXCLUDED_PACKAGES`.
`ShadowingClassLoader(ClassLoader enclosingClassLoader, boolean defaultExcludes)`
Create a new ShadowingClassLoader, decorating the given ClassLoader.

## Method Summary

Modifier and Type
Method
Description
`void`
`addTransformer(ClassFileTransformer transformer)`
Add the given ClassFileTransformer to the list of transformers that this ClassLoader will apply.
`void`
`copyTransformers(ShadowingClassLoader other)`
Copy all ClassFileTransformers from the given ClassLoader to the list of transformers that this ClassLoader will apply.
`URL`
`getResource(String name)`
`InputStream`
`getResourceAsStream(String name)`
`Enumeration<URL>`
`getResources(String name)`
`protected boolean`
`isEligibleForShadowing(String className)`
Determine whether the specified class is eligible for shadowing by this class loader.
`Class<?>`
`loadClass(String name)`

### Methods inherited from class org.springframework.core.DecoratingClassLoader

`excludeClass, excludePackage, isExcluded`

### Methods inherited from class java.lang.ClassLoader

`clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findClass, findLibrary, findLoadedClass, findResource, findResource, findResources, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### DEFAULT_EXCLUDED_PACKAGES

public static final String[] DEFAULT_EXCLUDED_PACKAGES
Packages that are excluded by default.

## Constructor Details

### ShadowingClassLoader

public ShadowingClassLoader(ClassLoader enclosingClassLoader)
Create a new ShadowingClassLoader, decorating the given ClassLoader, applying `DEFAULT_EXCLUDED_PACKAGES`.

Parameters:
  `enclosingClassLoader` - the ClassLoader to decorate
See Also:
  - `ShadowingClassLoader(ClassLoader, boolean)`

### ShadowingClassLoader

public ShadowingClassLoader(ClassLoader enclosingClassLoader, boolean defaultExcludes)
Create a new ShadowingClassLoader, decorating the given ClassLoader.

Parameters:
  `enclosingClassLoader` - the ClassLoader to decorate
  `defaultExcludes` - whether to apply `DEFAULT_EXCLUDED_PACKAGES`
Since:
  4.3.8

## Method Details

### addTransformer

public void addTransformer(ClassFileTransformer transformer)
Add the given ClassFileTransformer to the list of transformers that this ClassLoader will apply.

Parameters:
  `transformer` - the ClassFileTransformer

### copyTransformers

public void copyTransformers(ShadowingClassLoader other)
Copy all ClassFileTransformers from the given ClassLoader to the list of transformers that this ClassLoader will apply.

Parameters:
  `other` - the ClassLoader to copy from

### loadClass

public Class<?> loadClass(String name) throws ClassNotFoundException

Overrides:
  `loadClass` in class `ClassLoader`
Throws:
  `ClassNotFoundException`

### isEligibleForShadowing

protected boolean isEligibleForShadowing(String className)
Determine whether the specified class is eligible for shadowing by this class loader.

Parameters:
  `className` - the class name to check
Returns:
  whether the specified class is eligible
See Also:
  - `DecoratingClassLoader.isExcluded(java.lang.String)`

### getResource

public URL getResource(String name)

Overrides:
  `getResource` in class `ClassLoader`

### getResourceAsStream

@Nullable public InputStream getResourceAsStream(String name)

Overrides:
  `getResourceAsStream` in class `ClassLoader`

### getResources

public Enumeration<URL> getResources(String name) throws IOException

Overrides:
  `getResources` in class `ClassLoader`
Throws:
  `IOException`