Search code examples
springclassloader

Loading Spring context with specific classloader


How can I go about loading a Spring context with my own ClassLoader instance?


Solution

  • Many Spring Context Loader (for example ClassPathXmlApplicationContext ) are subclass of DefaultResourceLoader.

    DefaultResourceLoader has a constructor where you can specify the Classloader and also has a setClassLoader method.

    So it is your task to find a constructor of the Spring Context Loader you need, where you can specify the classloader, or just create it, and then use the set to set the classloader you want.