http://www.javadby.com/shiyongjiqiao/20071205/3737.html
java.lang.ClassNotFoundException
分析:
Digester类的getClassLoader方法
/**
* Return the class loader to be used for instantiating application objects
* when required. This is determined based upon the following rules:
* <ul>
* <li>The class loader set by <code>setClassLoader()</code>, if any</li>
* <li>The thread context class loader, if it exists and the
* <code>useContextClassLoader</code> property is set to true</li>
* <li>The class loader used to load the Digester class itself.
* </ul>
*/
public ClassLoader getClassLoader() {
if (this.classLoader != null) {
return (this.classLoader);
}
if (this.useContextClassLoader) {
ClassLoader classLoader =
Thread.currentThread().getContextClassLoader();
if (classLoader != null) {
return (classLoader);
}
}
return (this.getClass().getClassLoader());
}
默认使用当前线程上下文的ClassLoader或当前类的ClassLoader
解决方法:
1) 通过配置属性
Digester用来解析应用系统的配置文件,其本身也有很可配置的属性。
|
2)通过 setClassLoader
/**
* Set the class loader to be used for instantiating application objects
* when required.
*
* @param classLoader The new class loader to use, or <code>null</code>
* to revert to the standard rules
*/
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
如:digester.setClassLoader(this.getClass().getClassLoader());
本文探讨了Java中Digester类的getClassLoader方法的工作原理及其配置选项。详细介绍了如何通过设置Digester的属性来控制类的加载过程,包括使用线程上下文类加载器及自定义类加载器的方法。
851

被折叠的 条评论
为什么被折叠?



