[英]How can I configure a Spring BeanFactory with several bean configuration files?
I am sure that the above question has a straightforward answer but I couldn't easily find it (neither in the documentation nor on stackoverflow.com) 我敢肯定,上面的问题有一个简单的答案,但我很难找到它(既不在文档中,也不在stackoverflow.com上)
I got the notion that a BeanFactory/ApplicatioContext can be initialized with several bean configuration files. 我有一个可以用几个bean配置文件初始化BeanFactory / ApplicatioContext的想法。 Is that so?
是这样吗? And, if it is how can it be done?
而且,如果可以的话,怎么办呢?
Mark's answer is fine. 马克的回答很好。 You may also want to try this:
您可能还想尝试一下:
ApplicationContext context = new ClassPathXmlApplicationContext( new String[]{
"services.xml",
"daos.xml",
"webservices.xml",
"validators.xml"
});
See section 3.2.2.1 in the Spring Reference documentation. 请参阅Spring Reference文档中的3.2.2.1节 。 This describes how a configuration file can be split into separate configuration files that can then be imported into your main configuration file.
这描述了如何将配置文件拆分为单独的配置文件,然后将其导入到主配置文件中。
If you use an XML configuration file you can import multiple files from the classpath as such: 如果使用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>
While reading the above answers I had found the following class and its relevant constructor: 在阅读以上答案时,我发现了以下类及其相关的构造函数:
FileSystemXmlApplicationContext FileSystemXmlApplicationContext来
public FileSystemXmlApplicationContext(String[] configLocations,
boolean refresh,
ApplicationContext parent)
throws BeansException
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.