不同xml文件上的相同bean ID,会合并吗? [英] same bean id on different xml file, will it merge?

查看:116
本文介绍了不同xml文件上的相同bean ID,会合并吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读liferay源代码,发现使用相同的bean-id的2个xml文件.如果使用这种方式,所有属性将合并在一起吗?

i'm reading liferay source code and found out that 2 xml files using same bean-id. will all the properties merge together if using this way?

dynamic-data-spring
----------------------
    <bean id="liferayDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
        <property name="targetDataSource">
            <bean class="org.springframework.aop.framework.ProxyFactoryBean">
                <property name="targetSource" ref="dynamicDataSourceTargetSource" />
            </bean>
        </property>
    </bean>

infrastructure-spring.xml
----------------------
<bean id="liferayDataSource" class="org.springframework.jdbc.datasource.LazyConnectionDataSourceProxy">
        <property name="targetDataSource">
            <bean class="com.liferay.portal.dao.jdbc.util.DataSourceFactoryBean">
                <property name="propertyPrefix" value="jdbc.default." />
            </bean>
        </property>
    </bean>

推荐答案

否,Spring上下文将选择一个bean定义而不是另一个.选择哪个选项取决于初始化期间文件按什么顺序送入上下文.

No, the Spring context will select one bean definition over the other. Which one it chooses depends on what order the files are fed into the context during initialization.

日志记录应表明一个bean定义正在覆盖另一个bean定义.

Logging should indicate that one bean definition is overriding another.

这篇关于不同xml文件上的相同bean ID,会合并吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆