Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update spring beans dynamically. Is it possible?

Tags:

java

spring

Is there a way to update a Spring bean dynamically if the spring beans configuration changes?

E.g. assume that I have a spring bean with boolean property x and the spring beans has the value true when the application starts.

So spring creates the bean with the property x set to true.

Is there a way so that if I changes the property to x (while the application is running) that the property will be updated e.g. to false?

like image 344
Jim Avatar asked Nov 04 '22 06:11

Jim


2 Answers

Calling the setter for x setX() method will do that.

But it should not be a prototype bean.

like image 131
Mawia Avatar answered Nov 14 '22 22:11

Mawia


it is possible with the jrebel-spring integration. it monitors your configuration and TRIES to re-wire your beans at runtime.

Though i would not use it in production...only for playing around, testing etc

like image 24
wrm Avatar answered Nov 14 '22 22:11

wrm