Tag: classloader

动态加载spring xml配置

在一个春天的应用程序的启动时,我想扫描计算机上的路径,找到jar文件,并从他们的XML配置文件构建一个春天的应用程序上下文。 将jar文件添加到类路径并创建一个ApplicationContext都是可以的。 但是我从新的上下文中找不到任何bean。 所有需要的依赖关系都可以在计算机上的特定路径(通过maven复制插件)的jar文件中获得,这些依赖项在基本的spring项目(例如spring依赖项本身)中是需要的。 代码是(在Kotlin语言中): var loader = URLClassLoader(arrayOf(entry.toFile().toURL()), Thread.currentThread().contextClassLoader) … val context = ClassPathXmlApplicationContext("classpath*:/$name")//name is xml file. I'm sure the address in classpath is right. context is not creating when the address in wrong. for example: classpath://$name val services = context.getBeanNamesForType(IService::class.java)//services is empty 我已经尝试了许多其他的方式来加载XML,但没有一个是成功的。 例如: val beans = DefaultListableBeanFactory(applicationContext) val reader = XmlBeanDefinitionReader(beans) reader.beanClassLoader […]