the DefaultResourceLoader does NOT have the setter method Javadoc says it does.
From my source code of Spring (1.2.4):
Code:
public class DefaultResourceLoader implements ResourceLoader {
private ClassLoader classLoader;
/**
* Create a new DefaultResourceLoader.
* <p>ClassLoader access will happen via the thread context class loader on actual
* access (applying to the thread that does ClassPathResource calls).
* @see java.lang.Thread#getContextClassLoader()
*/
public DefaultResourceLoader() {
}
/**
* Create a new DefaultResourceLoader.
* @param classLoader the ClassLoader to load class path resources with,
* or null if using the thread context class loader on actual access
* (applying to the thread that does ClassPathResource calls)
*/
public DefaultResourceLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
/**
* Specify the ClassLoader to load class path resources with,
* or null if using the thread context class loader on actual access
* (applying to the thread that does ClassPathResource calls).
* <p>The default is that ClassLoader access will happen via the thread
* context class loader on actual access (applying to the thread that
* does ClassPathResource calls).
*/
public void setClassLoader(ClassLoader classLoader) {
this.classLoader = classLoader;
}
Look at the ClassPathXmlApplicationContext and it's ancesters code:
(from AbstractXmlApplicationContext)
Code:
/**
* Loads the bean definitions via an XmlBeanDefinitionReader.
* @see org.springframework.beans.factory.xml.XmlBeanDefinitionReader
* @see #initBeanDefinitionReader
* @see #loadBeanDefinitions
*/
protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws IOException {
...
// Configure the bean definition reader with this context's
// resource loading environment.
beanDefinitionReader.setResourceLoader(this);
if (getClassLoader() != null) {
beanDefinitionReader.setBeanClassLoader(getClassLoader());
}
...
}