Spring Cloud【Finchley】- 20使用@RefreshScope实现配置的刷新

简介: Spring Cloud【Finchley】- 20使用@RefreshScope实现配置的刷新

20190806093230928.jpg

概述


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上增加几个自定义的属性


20190411102732381.png

通过config server来访问下 ,确保能正常访问

http://localhost:9898/artisan-order-dev.yml


20190411103040591.png


配置文件


@ConfigurationProperties 参考之前的博客: Spring Boot2.x-03Spring Boot基础-基于properties的类型安全的配置


20190411102904966.png


注解说明 见注释

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

20190411103224846.png


将远端的配置修改下


2019041110365074.png

再次访问 http://localhost:8081/customizedPro


20190411103224846.png

还是没变。。。。

接下来通过curl POST手工刷新下吧,或者在git上设置webhooks 自动更新


使用curl 手工刷新配置

curl -v -X  POST http://localhost:9898/actuator/bus-refresh


20190411103346750.png


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


20190411104245882.png至此,通过@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

相关文章
|
1天前
|
消息中间件 开发框架 Java
什么是Spring Boot 自动配置?
Spring Boot 是一个流行的 Java 开发框架,它提供了许多便利的功能和工具,帮助开发者快速构建应用程序。其中一个最引人注目的特性是其强大的自动配置功能。
6 0
|
2天前
|
监控 安全 Java
Spring cloud原理详解
Spring cloud原理详解
13 0
|
2天前
|
安全 Java 开发者
深入理解Spring Boot配置绑定及其实战应用
【4月更文挑战第10天】本文详细探讨了Spring Boot中配置绑定的核心概念,并结合实战示例,展示了如何在项目中有效地使用这些技术来管理和绑定配置属性。
10 1
|
4天前
|
XML SQL Java
SpringCloud 基础配置
SpringCloud 基础配置
10 0
|
4天前
|
Java Spring
Spring文件配置以及获取
Spring文件配置以及获取
11 0
|
6天前
|
消息中间件 负载均衡 Java
【Spring Cloud 初探幽】
【Spring Cloud 初探幽】
14 1
|
8天前
|
Java 开发者 微服务
Spring Cloud原理详解
【5月更文挑战第4天】Spring Cloud是Spring生态系统中的微服务框架,包含配置管理、服务发现、断路器、API网关等工具,简化分布式系统开发。核心组件如Eureka(服务发现)、Config Server(配置中心)、Ribbon(负载均衡)、Hystrix(断路器)、Zuul(API网关)等。本文讨论了Spring Cloud的基本概念、核心组件、常见问题及解决策略,并提供代码示例,帮助开发者更好地理解和实践微服务架构。此外,还涵盖了服务通信方式、安全性、性能优化、自动化部署、服务网格和无服务器架构的融合等话题,揭示了微服务架构的未来趋势。
32 6
|
10天前
|
Java 微服务 Spring
Spring Boot中获取配置参数的几种方法
Spring Boot中获取配置参数的几种方法
21 2
|
12天前
|
JSON Java Apache
Spring Cloud Feign 使用Apache的HTTP Client替换Feign原生httpclient
Spring Cloud Feign 使用Apache的HTTP Client替换Feign原生httpclient