我们可以覆盖另一个配置中一个xml配置中声明的spring bean吗? [英] Can we override the spring beans declared in one xml config in another config?
问题描述
我是Spring的新手,所以这个问题可能有一个简单的答案所以如果我问傻话,请耐心等待。
I am a newbie to Spring so this question might have an easy answer so please bear me if i'm asking something silly.
我有一个全局的春天配置我想在许多应用程序中使用的文件,我想在不同的应用程序中以不同的方式覆盖几个bean的某些属性。你能建议最好的方法吗?
I have a global spring config file which I want to use in many applications and I would like to override some properties of few beans differently in different applications. Can you suggest the best way to do this?
例如,我在 global.xml中有类似的东西
。
<bean id="testInstance" class="testClass">
<property name="mem1" ref="val1"/>
<property name="mem2" ref="val2"/>
</bean>
现在,我想从 testInstance
中引用一个不同的弹簧配置,并在重写 mem1
后使用它。春天有可能吗?我是否需要使用自定义标签?
Now, I want to refer testInstance
from a different spring config and use it after overriding mem1
. Is it possible in spring? Do i need to use custom tags for that?
推荐答案
您可以在另一个xml配置中覆盖xml中定义的bean。但是如果你想利用@Configuration做同样的事情那么你就不走运了。 Spring不允许这样做。
You can override a bean defined in xml in another xml config. But if you want to leverage @Configuration to do same then you are out of luck. Spring does not allow to do that.
https://jira.springsource.org/browse/SPR-9567
这篇关于我们可以覆盖另一个配置中一个xml配置中声明的spring bean吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!