org.springframework.util包下的ClassUtils类有个静态方法:getDefaultClassLoader() 可以获取当前类加载器,如下:
public static ClassLoader getDefaultClassLoader() { ClassLoader cl = null; try { cl = Thread.currentThread().getContextClassLoader(); } catch (Throwable var3) { ; } if(cl == null) { cl = ClassUtils.class.getClassLoader(); if(cl == null) { try { cl = ClassLoader.getSystemClassLoader(); } catch (Throwable var2) { ; } } } return cl; }