Refresh Scope
A Spring @Bean that is marked as @RefreshScope will get special treatment when there is a configuration change. This 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, we probably want the holders of those connections to be able to complete what they are doing. Then the next time someone borrows a connection from the pool he gets one with the new URL.
###3. 在贴一下server 和 client 的配置代码
算了 不贴了,和以前一样的。
server:
Spring Cloud Config Server
client:
SpringCloud Config Client
@RefreshScope works (technically) on an @Configuration class, but it might lead to surprising behaviour: e.g. it does not mean that all the @Beans defined in that class are themselves @RefreshScope. Specifically, anything that depends on those beans cannot rely on them being updated when a refresh is initiated, unless it is itself in @RefreshScope (in which it will be rebuilt on a refresh and its dependencies re-injected, at which point they will be re-initialized from the refreshed @Configuration).这并不意味着在该类中定义的所有@Beans本身都是@RefreshScope。 具体来说,任何依赖这些bean的东西都不能依赖于它们在刷新时被更新,除非它本身在@RefreshScope中(在刷新时它将被重建,并且它的依赖关系被重新注入,在这一点上它们将被 从刷新的@Configuration重新初始化)。