Spring Cloud【Finchley】- 20使用@RefreshScope实现配置的刷新
作者:互联网
文章目录
概述
Spring Cloud实战-06使用/actuator/bus-refresh端点手动刷新配置 + 使用Spring Cloud Bus自动更新配置 中说到了@RefreshScope实现配置刷新,这里我们来通过一个例子再来感受下。
4个微服务工程:
- Eureka Server : https://github.com/yangshangwei/springcloud-o2o/tree/master/eureka-server 8762端口
- Artisan Config (Config Server):https://github.com/yangshangwei/springcloud-o2o/tree/master/artisan_config 9898端口
- Artisan Order (Config Client) :https://github.com/yangshangwei/springcloud-o2o/tree/master/artisan_order 8081端口
- 配置文件存储中心: https://github.com/yangshangwei/spring-cloud-config-center/blob/master/artisan-order-dev.yml
配置属性给artisan-order模块使用
我们在远端Git上增加几个自定义的属性
通过config server来访问下 ,确保能正常访问
http://localhost:9898/artisan-order-dev.yml
配置文件
@ConfigurationProperties 参考之前的博客: Spring Boot2.x-03Spring Boot基础-基于properties的类型安全的配置
注解说明 见注释
package com.artisan.order.config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Component;
@Data
@Component
//@ConfigurationProperties:告诉springboot将本类中所有属性和配置文件中相关的配置进行绑定;
// prefix="customized":指出将配置文件中customized下的所有属性进行一一映射
@ConfigurationProperties(prefix = "customized")
// 需要动态刷新配置,加上该注解
@RefreshScope
public class CustomizedConfig {
private String apiUrl;
private String apiCode;
}
测试下
package com.artisan.order.controller;
import com.artisan.order.config.CustomizedConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@Slf4j
public class CustomizedController {
@Autowired
private CustomizedConfig customizedConfig;
@GetMapping("/customizedPro")
public String getCustomizedProperties(){
String apiUrl = customizedConfig.getApiUrl();
String apiCode = customizedConfig.getApiCode();
log.info("apiUrl:{}, apiCode:{}",apiUrl,apiCode);
return "apiUrl:" + apiUrl + " , apiCode:" + apiCode;
}
}
启动服务,访问 http://localhost:8081/customizedPro
将远端的配置修改下
再次访问 http://localhost:8081/customizedPro
还是没变。。。。
接下来通过curl POST手工刷新下吧,或者在git上设置webhooks 自动更新
使用curl 手工刷新配置
curl -v -X POST http://localhost:9898/actuator/bus-refresh
Artisan Config 日志
2019-04-11 10:33:09.331 INFO 6120 --- [io-9898-exec-10] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2019-04-11 10:33:09.361 INFO 6120 --- [io-9898-exec-10] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@29501753: startup date [Thu Apr 11 10:33:09 CST 2019]; root of context hierarchy
2019-04-11 10:33:09.388 INFO 6120 --- [io-9898-exec-10] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-04-11 10:33:09.389 INFO 6120 --- [io-9898-exec-10] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$616b51b6] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-11 10:33:10.775 INFO 6120 --- [io-9898-exec-10] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2019-04-11 10:33:10.814 INFO 6120 --- [io-9898-exec-10] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2019-04-11 10:33:10.816 INFO 6120 --- [io-9898-exec-10] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@3db4246e: startup date [Thu Apr 11 10:33:10 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@29501753
2019-04-11 10:33:10.817 INFO 6120 --- [io-9898-exec-10] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-04-11 10:33:10.821 INFO 6120 --- [io-9898-exec-10] o.s.boot.SpringApplication : Started application in 2.851 seconds (JVM running for 1189.053)
2019-04-11 10:33:10.821 INFO 6120 --- [io-9898-exec-10] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@3db4246e: startup date [Thu Apr 11 10:33:10 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@29501753
2019-04-11 10:33:10.821 INFO 6120 --- [io-9898-exec-10] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@29501753: startup date [Thu Apr 11 10:33:09 CST 2019]; root of context hierarchy
2019-04-11 10:33:10.973 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2019-04-11 10:33:10.973 INFO 6120 --- [io-9898-exec-10] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-04-11 10:33:12.661 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Unregistering ...
2019-04-11 10:33:12.667 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : DiscoveryClient_ARTISAN-CONFIG/localhost:artisan-config:9898 - deregister status: 200
2019-04-11 10:33:12.676 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
2019-04-11 10:33:12.678 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-04-11 10:33:12.683 INFO 6120 --- [io-9898-exec-10] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2019-04-11 10:33:12.683 INFO 6120 --- [io-9898-exec-10] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2019-04-11 10:33:12.683 INFO 6120 --- [io-9898-exec-10] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2019-04-11 10:33:12.683 INFO 6120 --- [io-9898-exec-10] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2019-04-11 10:33:12.787 INFO 6120 --- [io-9898-exec-10] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2019-04-11 10:33:12.788 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2019-04-11 10:33:12.788 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2019-04-11 10:33:12.788 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2019-04-11 10:33:12.788 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Application is null : false
2019-04-11 10:33:12.788 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2019-04-11 10:33:12.788 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2019-04-11 10:33:12.788 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2019-04-11 10:33:12.793 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : The response status is 200
2019-04-11 10:33:12.794 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2019-04-11 10:33:12.795 INFO 6120 --- [io-9898-exec-10] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2019-04-11 10:33:12.795 INFO 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1554949992795 with initial instances count: 2
2019-04-11 10:33:12.796 INFO 6120 --- [io-9898-exec-10] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application artisan-config with eureka with status DOWN
2019-04-11 10:33:12.796 INFO 6120 --- [io-9898-exec-10] o.s.c.n.e.s.EurekaServiceRegistry : Registering application artisan-config with eureka with status UP
2019-04-11 10:33:12.796 WARN 6120 --- [io-9898-exec-10] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1554949992796, current=UP, previous=DOWN]
2019-04-11 10:33:12.796 INFO 6120 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_ARTISAN-CONFIG/localhost:artisan-config:9898: registering service...
2019-04-11 10:33:12.796 INFO 6120 --- [io-9898-exec-10] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
2019-04-11 10:33:12.811 INFO 6120 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_ARTISAN-CONFIG/localhost:artisan-config:9898 - registration status: 204
2019-04-11 10:33:17.884 INFO 6120 --- [nio-9898-exec-1] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2019-04-11 10:33:17.940 INFO 6120 --- [nio-9898-exec-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@a3fddba: startup date [Thu Apr 11 10:33:17 CST 2019]; root of context hierarchy
2019-04-11 10:33:17.948 INFO 6120 --- [nio-9898-exec-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-04-11 10:33:17.954 INFO 6120 --- [nio-9898-exec-1] o.s.c.c.s.e.NativeEnvironmentRepository : Adding property source: file:/E:/config-repo/artisan-order-dev.yml
2019-04-11 10:33:17.954 INFO 6120 --- [nio-9898-exec-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@a3fddba: startup date [Thu Apr 11 10:33:17 CST 2019]; root of context hierarchy
Artisan Order日志
2019-04-11 10:33:09.362 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2019-04-11 10:33:09.410 INFO 32200 --- [cGmIUdrkEeiSg-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@183976f5: startup date [Thu Apr 11 10:33:09 CST 2019]; root of context hierarchy
2019-04-11 10:33:09.497 INFO 32200 --- [cGmIUdrkEeiSg-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-04-11 10:33:09.498 INFO 32200 --- [cGmIUdrkEeiSg-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$99d50104] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2019-04-11 10:33:10.860 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2019-04-11 10:33:10.865 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-04-11 10:33:10.874 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-04-11 10:33:10.886 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2019-04-11 10:33:10.887 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2019-04-11 10:33:10.887 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2019-04-11 10:33:10.887 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2019-04-11 10:33:10.992 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2019-04-11 10:33:10.993 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2019-04-11 10:33:10.993 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2019-04-11 10:33:10.993 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2019-04-11 10:33:10.993 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Application is null : false
2019-04-11 10:33:10.993 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2019-04-11 10:33:10.993 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2019-04-11 10:33:10.993 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2019-04-11 10:33:10.999 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : The response status is 200
2019-04-11 10:33:11.000 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Not registering with Eureka server per configuration
2019-04-11 10:33:11.000 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1554949991000 with initial instances count: 2
2019-04-11 10:33:12.323 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.cloud.commons.util.InetUtils : Cannot determine local hostname
2019-04-11 10:33:12.367 INFO 32200 --- [cGmIUdrkEeiSg-1] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:9898/
2019-04-11 10:33:17.957 INFO 32200 --- [cGmIUdrkEeiSg-1] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=artisan-order, profiles=[dev], label=null, version=eecbfe24f58892e39e21cca0a51e117f953ea512, state=null
2019-04-11 10:33:17.957 INFO 32200 --- [cGmIUdrkEeiSg-1] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, MapPropertySource {name='https://github.com/yangshangwei/spring-cloud-config-center/artisan-order-dev.yml'}]}
2019-04-11 10:33:17.960 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2019-04-11 10:33:17.962 INFO 32200 --- [cGmIUdrkEeiSg-1] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@649f509: startup date [Thu Apr 11 10:33:17 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@183976f5
2019-04-11 10:33:17.966 INFO 32200 --- [cGmIUdrkEeiSg-1] f.a.AutowiredAnnotationBeanPostProcessor : JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
2019-04-11 10:33:17.979 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.boot.SpringApplication : Started application in 9.974 seconds (JVM running for 323.061)
2019-04-11 10:33:17.980 INFO 32200 --- [cGmIUdrkEeiSg-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@649f509: startup date [Thu Apr 11 10:33:17 CST 2019]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext@183976f5
2019-04-11 10:33:17.981 INFO 32200 --- [cGmIUdrkEeiSg-1] s.c.a.AnnotationConfigApplicationContext : Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@183976f5: startup date [Thu Apr 11 10:33:09 CST 2019]; root of context hierarchy
2019-04-11 10:33:17.982 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2019-04-11 10:33:17.992 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
2019-04-11 10:33:18.044 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Shutting down DiscoveryClient ...
2019-04-11 10:33:18.045 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2019-04-11 10:33:21.047 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Unregistering ...
2019-04-11 10:33:21.052 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : DiscoveryClient_ARTISAN-ORDER/localhost:artisan-order:8081 - deregister status: 200
2019-04-11 10:33:21.058 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Completed shut down of DiscoveryClient
2019-04-11 10:33:21.059 INFO 32200 --- [cGmIUdrkEeiSg-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2019-04-11 10:33:21.065 INFO 32200 --- [cGmIUdrkEeiSg-1] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2019-04-11 10:33:21.067 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2019-04-11 10:33:21.070 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2019-04-11 10:33:21.070 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
2019-04-11 10:33:21.070 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2019-04-11 10:33:21.070 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2019-04-11 10:33:21.138 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2019-04-11 10:33:21.139 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2019-04-11 10:33:21.139 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2019-04-11 10:33:21.139 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2019-04-11 10:33:21.139 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Application is null : false
2019-04-11 10:33:21.139 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2019-04-11 10:33:21.139 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2019-04-11 10:33:21.139 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2019-04-11 10:33:21.144 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : The response status is 200
2019-04-11 10:33:21.145 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Starting heartbeat executor: renew interval is: 30
2019-04-11 10:33:21.145 INFO 32200 --- [cGmIUdrkEeiSg-1] c.n.discovery.InstanceInfoReplicator : InstanceInfoReplicator onDemand update allowed rate per min is 4
2019-04-11 10:33:21.146 INFO 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Discovery Client initialized at timestamp 1554950001146 with initial instances count: 2
2019-04-11 10:33:21.146 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.c.n.e.s.EurekaServiceRegistry : Unregistering application artisan-order with eureka with status DOWN
2019-04-11 10:33:21.147 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.c.n.e.s.EurekaServiceRegistry : Registering application artisan-order with eureka with status UP
2019-04-11 10:33:21.147 WARN 32200 --- [cGmIUdrkEeiSg-1] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1554950001147, current=UP, previous=DOWN]
2019-04-11 10:33:21.147 INFO 32200 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_ARTISAN-ORDER/localhost:artisan-order:8081: registering service...
2019-04-11 10:33:21.148 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
2019-04-11 10:33:21.163 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [10.72.38.235:5672]
2019-04-11 10:33:21.164 INFO 32200 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_ARTISAN-ORDER/localhost:artisan-order:8081 - registration status: 204
2019-04-11 10:33:21.174 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.a.r.c.CachingConnectionFactory : Created new connection: rabbitConnectionFactory.publisher#408103:0/SimpleConnection@5110eae3 [delegate=amqp://guest@10.72.38.235:5672/, localPort= 55551]
2019-04-11 10:33:21.176 INFO 32200 --- [cGmIUdrkEeiSg-1] o.s.amqp.rabbit.core.RabbitAdmin : Auto-declaring a non-durable, auto-delete, or exclusive Queue (springCloudBus.anonymous.WHKGXmOwQcGmIUdrkEeiSg) durable:false, auto-delete:true, exclusive:true. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.
无需重启,再次访问 http://localhost:8081/customizedPro
至此,通过@RefreshScope+手工刷新的方式实现了无需重启应用刷新配置的功能。
通过RabbitMQ实现自动刷新请移步我的另外一篇博客:Spring Cloud实战-06使用/actuator/bus-refresh端点手动刷新配置 + 使用Spring Cloud Bus自动更新配置
代码
- Eureka Server : https://github.com/yangshangwei/springcloud-o2o/tree/master/eureka-server 8762端口
- Artisan Config (Config Server):https://github.com/yangshangwei/springcloud-o2o/tree/master/artisan_config 9898端口
- Artisan Order (Config Client) :https://github.com/yangshangwei/springcloud-o2o/tree/master/artisan_order 8081端口
- 配置文件存储中心: https://github.com/yangshangwei/spring-cloud-config-center/blob/master/artisan-order-dev.yml
标签:11,10,---,20,04,33,Spring,Finchley,2019 来源: https://blog.51cto.com/u_15239532/2836496