Class FilteredClassLoader
- java.lang.Object
- java.lang.ClassLoader
- java.security.SecureClassLoader
- java.net.URLClassLoader
- org.springframework.boot.test.context.FilteredClassLoader
- All Implemented Interfaces:
Closeable
,AutoCloseable
public class FilteredClassLoader extends URLClassLoader
TestURLClassLoader
that can filter the classes and resources it can load.- Since:
- 2.0.0
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FilteredClassLoader.ClassFilter
Filter to restrict the classes that can be loaded.static class
FilteredClassLoader.ClassPathResourceFilter
Filter to restrict the resources that can be loaded.static class
FilteredClassLoader.PackageFilter
Filter to restrict the packages that can be loaded.
Constructor Summary
Constructors Constructor Description FilteredClassLoader(Class<?>... hiddenClasses)
Create aFilteredClassLoader
that hides the given classes.FilteredClassLoader(String... hiddenPackages)
Create aFilteredClassLoader
that hides classes from the given packages.FilteredClassLoader(Predicate<String>... filters)
Create aFilteredClassLoader
that filters based on the given predicate.FilteredClassLoader(org.springframework.core.io.ClassPathResource... hiddenResources)
Create aFilteredClassLoader
that hides resources from the givenclasspath resources
.
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description URL
getResource(String name)
protected Class<?>
loadClass(String name, boolean resolve)
Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getResourceAsStream, getURLs, newInstance, newInstance
Methods inherited from class java.security.SecureClassLoader
defineClass, defineClass
Methods inherited from class java.lang.ClassLoader
clearAssertionStatus, defineClass, defineClass, defineClass, defineClass, definePackage, findClass, findLibrary, findLoadedClass, findResource, findSystemClass, getClassLoadingLock, getDefinedPackage, getDefinedPackages, getName, getPackage, getPackages, getParent, getPlatformClassLoader, getResources, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSigners
Constructor Detail
FilteredClassLoader
public FilteredClassLoader(Class<?>... hiddenClasses)
Create aFilteredClassLoader
that hides the given classes.- Parameters:
hiddenClasses
- the classes to hide
FilteredClassLoader
public FilteredClassLoader(String... hiddenPackages)
Create aFilteredClassLoader
that hides classes from the given packages.- Parameters:
hiddenPackages
- the packages to hide
FilteredClassLoader
public FilteredClassLoader(org.springframework.core.io.ClassPathResource... hiddenResources)
Create aFilteredClassLoader
that hides resources from the givenclasspath resources
.- Parameters:
hiddenResources
- the resources to hide- Since:
- 2.1.0
FilteredClassLoader
@SafeVarargs public FilteredClassLoader(Predicate<String>... filters)
Create aFilteredClassLoader
that filters based on the given predicate.- Parameters:
filters
- a set of filters to determine when a class name or resource should be hidden. Aresult
oftrue
indicates a filtered class or resource. The input of the predicate can either be the binary name of a class or a resource name.
Method Detail
loadClass
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException
- Overrides:
loadClass
in classClassLoader
- Throws:
ClassNotFoundException
getResource
public URL getResource(String name)
- Overrides:
getResource
in classClassLoader