接口 SmartClassLoader
If a ClassLoader does not implement this interface, then all the classes obtained from it should be considered as not reloadable (i.e. cacheable).
- 从以下版本开始:
- 4.0
- 作者:
- Juergen Hoeller, TODAY 2021/10/30 17:55
-
方法概要
修饰符和类型方法说明default ClassLoaderReturn the original ClassLoader for this SmartClassLoader, or potentially the present loader itself if it is self-sufficient.default booleanisClassReloadable(Class<?> clazz) Determine whether the given class is reloadable (in this ClassLoader).default Class<?>publicDefineClass(String name, byte[] b, ProtectionDomain protectionDomain) Define a custom class (typically a CGLIB proxy class) in this class loader.
-
方法详细资料
-
isClassReloadable
Determine whether the given class is reloadable (in this ClassLoader).Typically used to check whether the result may be cached (for this ClassLoader) or whether it should be reobtained every time. The default implementation always returns
false.- 参数:
clazz- the class to check (usually loaded from this ClassLoader)- 返回:
- whether the class should be expected to appear in a reloaded
version (with a different
Classobject) later on
-
getOriginalClassLoader
Return the original ClassLoader for this SmartClassLoader, or potentially the present loader itself if it is self-sufficient.The default implementation returns the local ClassLoader reference as-is. In case of a reloadable or other selectively overriding ClassLoader which commonly deals with unaffected classes from a base application class loader, this should get implemented to return the original ClassLoader that the present loader got derived from (e.g. through
return getParent();).This gets specifically used in AOP framework to determine the class loader for a specific proxy in case the target class has not been defined in the present class loader. In case of a reloadable class loader, we prefer the base application class loader for proxying general classes not defined in the reloadable class loader itself.
- 返回:
- the original ClassLoader (the same reference by default)
- 另请参阅:
-
publicDefineClass
default Class<?> publicDefineClass(String name, byte[] b, @Nullable ProtectionDomain protectionDomain) Define a custom class (typically a CGLIB proxy class) in this class loader.This is a public equivalent of the protected
defineClass(String, byte[], int, int, ProtectionDomain)method inClassLoaderwhich is traditionally invoked via reflection. A concrete implementation in a custom class loader should simply delegate to that protected method in order to make classloader-specific definitions publicly available without "illegal access" warnings on JDK 9+:return defineClass(name, b, 0, b.length, protectionDomain). Note that the JDK 9+Lookup#defineClassmethod does not support a custom target class loader for the new definition; it rather always defines the class in the same class loader as the lookup's context class.- 参数:
name- the name of the classb- the bytes defining the classprotectionDomain- the protection domain for the class, if any- 返回:
- the newly created class
- 抛出:
LinkageError- in case of a bad class definitionSecurityException- in case of an invalid definition attemptUnsupportedOperationException- in case of a custom definition attempt not being possible (thrown by the default implementation in this interface)- 另请参阅:
-