From 1410af9cb826b34118c9116e018e80892e1c1e75 Mon Sep 17 00:00:00 2001
From: buildmaster @ConfigurationProperties does not cover
To address those concerns, we have @RefreshScope.
When there is a configuration change, a Spring @Bean that is marked as @RefreshScope gets special treatment.
This feature addresses the problem of stateful beans that only get their configuration injected when they are initialized.
For instance, if a DataSource has open connections when the database URL is changed via the Environment, you probably want the holders of those connections to be able to complete what they are doing.
-Then, the next time something borrows a connection from the pool, it gets one with the new URL.
Refresh scope beans are lazy proxies that initialize when they are used (that is, when a method is called), and the scope acts as a cache of initialized values. +Then, the next time something borrows a connection from the pool, it gets one with the new URL.
Sometimes, it might even be mandatory to apply the @RefreshScope
+annotation on some beans which can be only initialized once. If a bean
+is "immutable", you will have to either annotate the bean with @RefreshScope
+or specify the classname under the property key
+spring.cloud.refresh.extra-refreshable.
Refresh scope beans are lazy proxies that initialize when they are used (that is, when a method is called), and the scope acts as a cache of initialized values. To force a bean to re-initialize on the next method call, you must invalidate its cache entry.
The RefreshScope is a bean in the context and has a public refreshAll() method to refresh all beans in the scope by clearing the target cache.
The /refresh endpoint exposes this functionality (over HTTP or JMX).
To refresh an individual bean by name, there is also a refresh(String) method.
To expose the /refresh endpoint, you need to add following configuration to your application:
management: diff --git a/single/spring-cloud-commons.html b/single/spring-cloud-commons.html index 0c27b32f..88eedd0f 100644 --- a/single/spring-cloud-commons.html +++ b/single/spring-cloud-commons.html @@ -73,7 +73,11 @@ Re-binding@ConfigurationPropertiesdoes not cover To address those concerns, we have@RefreshScope.
When there is a configuration change, a Spring @Bean that is marked as @RefreshScope gets special treatment.
This feature addresses the problem of stateful beans that only get their configuration injected when they are initialized.
For instance, if a DataSource has open connections when the database URL is changed via the Environment, you probably want the holders of those connections to be able to complete what they are doing.
-Then, the next time something borrows a connection from the pool, it gets one with the new URL.
Refresh scope beans are lazy proxies that initialize when they are used (that is, when a method is called), and the scope acts as a cache of initialized values. +Then, the next time something borrows a connection from the pool, it gets one with the new URL.
Sometimes, it might even be mandatory to apply the @RefreshScope
+annotation on some beans which can be only initialized once. If a bean
+is "immutable", you will have to either annotate the bean with @RefreshScope
+or specify the classname under the property key
+spring.cloud.refresh.extra-refreshable.
Refresh scope beans are lazy proxies that initialize when they are used (that is, when a method is called), and the scope acts as a cache of initialized values. To force a bean to re-initialize on the next method call, you must invalidate its cache entry.
The RefreshScope is a bean in the context and has a public refreshAll() method to refresh all beans in the scope by clearing the target cache.
The /refresh endpoint exposes this functionality (over HTTP or JMX).
To refresh an individual bean by name, there is also a refresh(String) method.
To expose the /refresh endpoint, you need to add following configuration to your application:
management: diff --git a/spring-cloud-commons.xml b/spring-cloud-commons.xml index e3d24479..8c34bdd2 100644 --- a/spring-cloud-commons.xml +++ b/spring-cloud-commons.xml @@ -179,6 +179,11 @@ To address those concerns, we have@RefreshScope . This feature addresses the problem of stateful beans that only get their configuration injected when they are initialized. For instance, if aDataSource has open connections when the database URL is changed via theEnvironment , you probably want the holders of those connections to be able to complete what they are doing. Then, the next time something borrows a connection from the pool, it gets one with the new URL. +Sometimes, it might even be mandatory to apply the @RefreshScope +annotation on some beans which can be only initialized once. If a bean +is "immutable", you will have to either annotate the bean with@RefreshScope +or specify the classname under the property key +spring.cloud.refresh.extra-refreshable .Refresh scope beans are lazy proxies that initialize when they are used (that is, when a method is called), and the scope acts as a cache of initialized values. To force a bean to re-initialize on the next method call, you must invalidate its cache entry. The RefreshScope is a bean in the context and has a publicrefreshAll() method to refresh all beans in the scope by clearing the target cache.