7

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?

Buchi
  • 1,322
  • 4
  • 14
  • 33
  • 2
    You can, but you then need to override the testInstance. (http://stackoverflow.com/questions/5849192/springs-overriding-bean) – Kurt Du Bois Feb 01 '12 at 09:59
  • Use search first! :) Check this out: http://stackoverflow.com/questions/5849192/springs-overriding-bean And this: http://beradrian.wordpress.com/2011/05/08/overriding-spring-beans/ – Matjaz Muhic Feb 01 '12 at 10:01

1 Answers1

4

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

Jany
  • 73
  • 6