Spring类加载器的选择逻辑

来源:互联网 发布:清理数据 英文 编辑:程序博客网 时间:2024/05/17 20:12
public static ClassLoader getDefaultClassLoader() {        ClassLoader cl = null;        try {            cl = Thread.currentThread().getContextClassLoader();        }        catch (Throwable ex) {            // Cannot access thread context ClassLoader - falling back...        }        if (cl == null) {            // No thread context class loader -> use class loader of this class.            cl = ClassUtils.class.getClassLoader();            if (cl == null) {                // getClassLoader() returning null indicates the bootstrap ClassLoader                try {                    cl = ClassLoader.getSystemClassLoader();                }                catch (Throwable ex) {                    // Cannot access system ClassLoader - oh well, maybe the caller can live with null...                }            }        }        return cl;    }

总结:选择顺序为 线程上下文加载器-》 加载 ClassUtils.class的加载器-》java的系统加载器

原创粉丝点击