Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we override the spring beans declared in one xml config in another config?

Tags:

java

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.

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?

For example, I've something like this in global.xml.

<bean id="testInstance" class="testClass">
    <property name="mem1" ref="val1"/>
    <property name="mem2" ref="val2"/>
</bean>

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?

like image 557
Buchi Avatar asked Feb 01 '12 09:02

Buchi


1 Answers

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

like image 58
Jany Avatar answered Oct 13 '22 10:10

Jany