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,org.springframework.core.SmartClassLoader
public class FilteredClassLoader
extends URLClassLoader
implements org.springframework.core.SmartClassLoader
Test
URLClassLoader that can filter the classes and resources it can load.- Since:
- 2.0.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classFilter to restrict the classes that can be loaded.static final classFilter to restrict the resources that can be loaded.static final classFilter to restrict the packages that can be loaded. -
Constructor Summary
ConstructorsConstructorDescriptionFilteredClassLoader(Class<?>... hiddenClasses) Create aFilteredClassLoaderthat hides the given classes.FilteredClassLoader(String... hiddenPackages) Create aFilteredClassLoaderthat hides classes from the given packages.FilteredClassLoader(Predicate<String>... filters) Create aFilteredClassLoaderthat filters based on the given predicate.FilteredClassLoader(org.springframework.core.io.ClassPathResource... hiddenResources) Create aFilteredClassLoaderthat hides resources from the givenclasspath resources. -
Method Summary
Modifier and TypeMethodDescriptiongetResource(String name) getResourceAsStream(String name) getResources(String name) protected Class<?>Class<?>publicDefineClass(String name, byte[] b, ProtectionDomain protectionDomain) Methods inherited from class java.net.URLClassLoader
addURL, close, definePackage, findClass, findResource, findResources, getPermissions, getURLs, newInstance, newInstanceMethods inherited from class java.security.SecureClassLoader
defineClass, defineClassMethods 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, getSystemClassLoader, getSystemResource, getSystemResourceAsStream, getSystemResources, getUnnamedModule, isRegisteredAsParallelCapable, loadClass, registerAsParallelCapable, resolveClass, resources, setClassAssertionStatus, setDefaultAssertionStatus, setPackageAssertionStatus, setSignersMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.springframework.core.SmartClassLoader
getOriginalClassLoader, isClassReloadable
-
Constructor Details
-
FilteredClassLoader
Create aFilteredClassLoaderthat hides the given classes.- Parameters:
hiddenClasses- the classes to hide
-
FilteredClassLoader
Create aFilteredClassLoaderthat hides classes from the given packages.- Parameters:
hiddenPackages- the packages to hide
-
FilteredClassLoader
public FilteredClassLoader(org.springframework.core.io.ClassPathResource... hiddenResources) Create aFilteredClassLoaderthat hides resources from the givenclasspath resources.- Parameters:
hiddenResources- the resources to hide- Since:
- 2.1.0
-
FilteredClassLoader
Create aFilteredClassLoaderthat filters based on the given predicate.- Parameters:
filters- a set of filters to determine when a class name or resource should be hidden. Aresultoftrueindicates a filtered class or resource. The input of the predicate can either be the binary name of a class or a resource name.
-
-
Method Details
-
loadClass
- Overrides:
loadClassin classClassLoader- Throws:
ClassNotFoundException
-
getResource
- Overrides:
getResourcein classClassLoader
-
getResources
- Overrides:
getResourcesin classClassLoader- Throws:
IOException
-
getResourceAsStream
- Overrides:
getResourceAsStreamin classURLClassLoader
-
publicDefineClass
- Specified by:
publicDefineClassin interfaceorg.springframework.core.SmartClassLoader
-