public class ContextClassLoaderInjector extends Object
Modifier and Type | Class and Description |
---|---|
static interface |
ContextClassLoaderInjector.SupplierWithException<T>
supplier which can throw exceptions
|
Constructor and Description |
---|
ContextClassLoaderInjector() |
Modifier and Type | Method and Description |
---|---|
static Object |
createInjectedObject(Class<?> superClass,
ClassLoader contextClassLoader)
Create an injected object which has been injected with specifying the thread context class loader during all its methods invocation.
|
static <T> T |
switchContextClassLoader(ClassLoader contextClassLoader,
ContextClassLoaderInjector.SupplierWithException<T> func)
Switch the thread context class loader during the execution of the function
|
public static Object createInjectedObject(Class<?> superClass, ClassLoader contextClassLoader) throws Exception
superClass
- The class whose object methods need to be injectedcontextClassLoader
- the thread context class loader to inject in all the methods of the class objectException
public static <T> T switchContextClassLoader(ClassLoader contextClassLoader, ContextClassLoaderInjector.SupplierWithException<T> func) throws Exception
T
- return type of functioncontextClassLoader
- the specified thread context class loaderfunc
- the function which needs to be set thread context class loaderException
- the exception thrown during function execution