锁定老帖子 主题:Spring加载多个配置文件
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2007-10-12
关于Spring加载多个配置文件的方式: 1. 在web.xml文件中注册: <servlet> 在一个配置文件中的bean想要引用另一个文件中的bean,可以使用<property name="dataSource" ><ref bean="dataSource"/></property>这样拿到。注意是bean=, 而不是local = . 如果是使用local = .表示从当前配置文件中寻找bean, 如果bean是在其他文件中则用bean = 来找。 2. ApplicationContext act = new ClassPathXmlApplicationContext(new String[]{"bean1.xml","bean2.xml"}); BeanDefinitionRegistry reg = new DefaultListableBeanFactory(); XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(reg); reader.loadBeanDefinitions(new ClassPathResource("bean1.xml")); reader.loadBeanDefinitions(new ClassPathResource("bean2.xml")); BeanFactory bf = (BeanFactory)reg; 3. struts与spring集成时,还可选择struts插件来集成spring配置文件。 在struts的配置文件struts-config-*.xml最后添加: <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-01-18
web的我也配了多个配置文件,就看看ApplicationConext怎么加载, 懒得看文档, 呵呵,谢谢
|
|
返回顶楼 | |
浏览 7498 次