3

I am drawing a blank on this for some reason. I have a multi-module Spring/Maven project. In module1 I define a singleton bean called "info" and it works within module1 just fine.

However module2 in this project (which depends on module1) has improvements on property values for the "info" bean. Module2's Spring configuration already includes Module1's configuration. What is the Spring configuration I should use to set properties on the "info" bean defined in this subsequent module?

Dave
  • 21,524
  • 28
  • 141
  • 221
  • 1
    I'm pretty sure this isn't possible. I think the best you could hope for is to create the new bean with a different id and set the parent attribute to your original bean. Then, you'd have to ensure that the new bean is getting set into the module2 beans that depend on it. – dlawrence Sep 17 '11 at 03:02
  • You were right. I had to re-architect both modules and take a new approach. Thanks. – Dave Sep 19 '11 at 06:52

2 Answers2

1

Since Spring 2.5 there is a PropertyOverrideConfigurer. Maybe that's what you are searching for

http://static.springsource.org/spring/docs/2.5.x/reference/beans.html#beans-factory-overrideconfigurer

There is a small example on this page http://ondra.zizka.cz/stranky/programovani/java/howto-substitutions_in_spring_configuration-tutorial.texy

user948392
  • 176
  • 8
  • This is close to what I need except the values supplied must come from a property file...I need to compute mine through Spring expressions. Thanks anyway though...this was good to know about. – Dave Sep 18 '11 at 05:49
  • Ok, i must say thats the only way i know. Perhaps you need to write your own bean thats responsible for overwriting the properties. Have a look at the applyPropertyValue Method from the PropertyOverrideConfigurer. That's the way how you can do this. – user948392 Sep 18 '11 at 10:13
0

Create a new "info" bean in module2, configuring it the way specific to the needs of module 2. You would do something like this in your module 2 configuration:

<import resource="classpath:/META-INF/module1-config.xml"/>
<bean name="info" class="Module1class"/>

This should inject the right "info" into the dependent beans

Biju Kunjummen
  • 49,138
  • 14
  • 112
  • 125
  • When I do this my app uses the second "info" bean and the values put into the first info bean are not there. In other words, the second bean definition just makes a second bean...that replaces the first rather than changes some values. – Dave Sep 18 '11 at 06:12