0

For this bean :

<bean id="myBean"class="com.MyBean">
    <property name="test" value="mytest"/>              
</bean>

What is an approprate method of update the property value at runtime ?

I've read about Lookup method injection : http://docs.spring.io/spring/docs/3.0.0.M3/reference/html/ch04s03.html#beans-factory-method-injection

But I don't think this is suited to this scenario as I want to change the value of a property not re-instantiate a Spring managed bean, but perhaps this is the same thing in Spring ?

blue-sky
  • 51,962
  • 152
  • 427
  • 752
  • 1
    Get the bean and call its setter: `((MyBean)context.getBean("myBean")).setTest("someValue")` – Sotirios Delimanolis Nov 28 '13 at 15:36
  • @Adrian did you check this http://stackoverflow.com/questions/9974246/spring-how-to-do-transparent-runtime-changeable-property-configuration – erhun Nov 28 '13 at 15:43
  • 1
    you could have the properties coming from a database and use some caching to avoid querying the database too often or use ReloadablePropertiesAnnotation like explained http://stackoverflow.com/questions/20262868/refresh-property-placeholder-mechanism-at-spring/20263835#20263835 – Frederic Close Nov 28 '13 at 16:41
  • Is it really a property? Maybe it's better to conceive myBean as a service that has `SomeClass getMyTest()` method and calculates some value? You can also wrap the bean with a service like this. – Boris Treukhov Nov 28 '13 at 19:55

0 Answers0