[英]Spring configure the same bean at multiple @Configuration files
[英]How can I configure a Spring BeanFactory with several bean configuration files?
我敢肯定,上面的问题有一个简单的答案,但我很难找到它(既不在文档中,也不在stackoverflow.com上)
我有一个可以用几个bean配置文件初始化BeanFactory / ApplicatioContext的想法。 是这样吗? 而且,如果可以的话,怎么办呢?
马克的回答很好。 您可能还想尝试一下:
ApplicationContext context = new ClassPathXmlApplicationContext( new String[]{
"services.xml",
"daos.xml",
"webservices.xml",
"validators.xml"
});
请参阅Spring Reference文档中的3.2.2.1节 。 这描述了如何将配置文件拆分为单独的配置文件,然后将其导入到主配置文件中。
如果使用XML配置文件,则可以这样从类路径导入多个文件:
<?xml version="1.0" encoding="UTF-8"?>
<beans>
<import resource="classpath:/path/to/file/one.xml" />
<import resource="classpath:/path/to/file/two.xml" />
</beans>
在阅读以上答案时,我发现了以下类及其相关的构造函数:
FileSystemXmlApplicationContext来
public FileSystemXmlApplicationContext(String[] configLocations,
boolean refresh,
ApplicationContext parent)
throws BeansException
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.