3

I have a spring-boot project and I manage to configure external configuration which will work both under external servlet container and with embedded servlet container(you can see details here: External configuration for spring-boot application ) Now I want to make this configuration re-loadable at run-time. Any idea?

Community
  • 1
  • 1
Aram Aslanyan
  • 745
  • 3
  • 11
  • 18

3 Answers3

4

Take a look at the spring-cloud-config project (http://cloud.spring.io/spring-cloud-config), it allows reloading of configurations (the focus is on loading from a central server, not sure if it covers local files as well). Beans can be annotated with a @RefreshScope to re-initialize when the config is changed.

Lukas Hinsch
  • 1,840
  • 14
  • 8
  • We added @RefreshScope above our Property file reader, yet we dont' see the scope being refreshed, i.e the new properties are not read. Anything else we need to do? Should we call the /refresh endpoint to reload the properties file? Or is there a delay we can add on which the reload of properties happen. – Pavanraotk Jun 13 '16 at 12:42
  • If an application supports configuration refresh, that functionality needs to be integration tested to make sure the semantics are supported consistently across application components (Spring or otherwise). Usually the process of defining, authoring and executing those tests is cost prohibitive. For most applications, the benefits are simply not worth the cost when rolling upgrades are fast and easy. If your rolling updates are not both fast and easy, then that is a much higher priority, in the scheme of things. – Charlie Reitzel Dec 14 '21 at 17:13
0

I think this is not possible; at least not easily. If you change your config and want these changes to be reflected in your spring context, all managed beans and components dependent on that config would have to be "reinitialized" or updated with the new config values. I guess this would somehow result in a "restart" of your spring context.

edit: maybe with jmx sth like this would be possible. or you call the refresh endpoint of springboot

-1

In my experience, configuration changes in a shared environment (DEV, QA, PROD, etc.) are often shared across a cluster or farm of application instances. Thus, the best approach to pushing out configuration changes, imo, is to execute a rolling restart across the cluster. This approach also works well in the cloud w/ or without containers.

If you need to keep your sessions intact through this process, that needs to be part of your HA plan in any case.

Charlie Reitzel
  • 809
  • 8
  • 13