javascript
Spring Cloud【Finchley】- 20使用@RefreshScope实现配置的刷新
文章目錄
- 概述
- 配置屬性給artisan-order模塊使用
- 配置文件
- 使用curl 手工刷新配置
- 代碼
概述
Spring Cloud實戰(zhàn)-06使用/actuator/bus-refresh端點手動刷新配置 + 使用Spring Cloud Bus自動更新配置 中說到了@RefreshScope實現(xiàn)配置刷新,這里我們來通過一個例子再來感受下。
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") // 需要動態(tài)刷新配置,加上該注解 @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 {@Autowiredprivate 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-refreshArtisan 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 hierarchyArtisan 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+手工刷新的方式實現(xiàn)了無需重啟應用刷新配置的功能。
通過RabbitMQ實現(xiàn)自動刷新請移步我的另外一篇博客:Spring Cloud實戰(zhàn)-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
總結
以上是生活随笔為你收集整理的Spring Cloud【Finchley】- 20使用@RefreshScope实现配置的刷新的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Spring Cloud【Finchle
- 下一篇: Spring Boot2.x-15 整合