public static ClassLoader overrideThreadContextClassLoader ( ClassLoader classLoaderToUse ) { Thread currentThread = Thread . currentThread ( ) ; ClassLoader threadContextClassLoader = currentThread . getContextClassLoader ( ) ; if ( classLoaderToUse != null && ! classLoaderToUse . equals ( threadContextClassLoader ) ) { currentThread . setContextClassLoader ( classLoaderToUse ) ; return threadContextClassLoader ; } else { return null ; } }
Override the thread context ClassLoader with the environment s bean ClassLoader if necessary i . e . if the bean ClassLoader is not equivalent to the thread context ClassLoader already .