Reputation: 4778
is there a way to change the properties of a spring bean (service) at runtime? I'm using grails for a small app, where the user is able to change some settings. These settings are written into a property file, which is in the ext config params at grails. So when I restart the application, the properties are read in and the bean is init with this changes, is there a way to reload my service without a full restart?
What I would like to achieve that the user can pass is settings to the service and everything is available at runtime.
Upvotes: 1
Views: 1322
Reputation: 5805
I think you need to redesign the way you're approaching this requirement. It is a huge code smell that your user can do things through the UI of the app that require a restart for them to take-effect.
Having said that, I think you can probably grab a hold of the ApplicationContext object, catch the event in the UI, and replace the instance of your service, since you should have access to the new configuration values in that context. But I would advise against it, it's a hacky solution that will come back to haunt you :)
Upvotes: 1