????1??ClassLoader????????????????????????????????Class??ClassLoader?????????????????????JVM??????????“?????”??????Thread????getContextClassLoader()??setContextClassLoader()??????
????2??ClassLoader???????URLClassLoader????????????????????class????jar?????URL????????????????????Class??
????3??ClassLoader?и????????parent?????ClassLoader???Class???????????????parent????????Class????е???????????????????????????ClassLoader????????????????磺
import java.net.URL;
import java.net.URLClassLoader;
/**
* ???????????Class??????????parent
*/
public class OverridingClassLoader extends URLClassLoader
{
private final ClassLoader parent;
public OverridingClassLoader(URL[] urls?? ClassLoader parent)
{
super(urls?? null);
this.parent = parent;
}
@Override
public Class<?> loadClass(String name) throws ClassNotFoundException
{
try
{
return super.loadClass(name);
} catch (Exception e)
{
return parent.loadClass(name);
}
}
}
????4??JVM??????????????ж????ClassLoader??????????????????????????????????Class???????????????Class?????????????????????Щ????????磬??????????Person??Student?м?й???????????ClassLoader??????JVM????????ClassLoader???????jar?????????????Person??????????Student??????Person??????κι????instanceof??isAssignableFrom??????false??
????5????????????????Spring??Hadoop???????????Thread.currentThread().getContextClassLoader()?????ClassLoader??????????????????????????????????ClassLoader????????????Thread.currentThread().setContextClassLoader()?????ClassLoader??????Tomcat?????????????webapp??Thread.currentThread().getContextClassLoader()?????????webapp???????WebappClassLoader???????????ò??jar????webapp??????????