问题描述
如何使用自己的ClassLoader
实例加载Spring上下文?
How can I go about loading a Spring context with my own ClassLoader
instance?
推荐答案
许多Spring Context Loader(例如 ClassPathXmlApplicationContext )是 DefaultResourceLoader .
Many Spring Context Loader (for example ClassPathXmlApplicationContext) are subclass of DefaultResourceLoader.
DefaultResourceLoader
具有构造器,您可以在其中指定Classloader并具有 setClassLoader
方法.
DefaultResourceLoader
has a constructor where you can specify the Classloader and also has a setClassLoader
method.
因此,找到所需的Spring Context Loader的构造函数是您的任务,您可以在其中指定类加载器,也可以只创建它,然后使用该集合来设置所需的类加载器.
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.
这篇关于使用特定的类加载器加载Spring上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!