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

相关文章
|
10月前
|
负载均衡 监控 Java
Spring Cloud Gateway 全解析:路由配置、断言规则与过滤器实战指南
本文详细介绍了 Spring Cloud Gateway 的核心功能与实践配置。首先讲解了网关模块的创建流程,包括依赖引入(gateway、nacos 服务发现、负载均衡)、端口与服务发现配置,以及路由规则的设置(需注意路径前缀重复与优先级 order)。接着深入解析路由断言,涵盖 After、Before、Path 等 12 种内置断言的参数、作用及配置示例,并说明了自定义断言的实现方法。随后重点阐述过滤器机制,区分路由过滤器(如 AddRequestHeader、RewritePath、RequestRateLimiter 等)与全局过滤器的作用范围与配置方式,提
Spring Cloud Gateway 全解析:路由配置、断言规则与过滤器实战指南
|
10月前
|
Java 关系型数据库 MySQL
Spring Boot自动配置:魔法背后的秘密
Spring Boot 自动配置揭秘:只需简单配置即可启动项目,背后依赖“约定大于配置”与条件化装配。核心在于 `@EnableAutoConfiguration` 注解与 `@Conditional` 系列条件判断,通过 `spring.factories` 或 `AutoConfiguration.imports` 加载配置类,实现按需自动装配 Bean。
|
10月前
|
人工智能 Java 开发者
【Spring】原理解析:Spring Boot 自动配置
Spring Boot通过“约定优于配置”的设计理念,自动检测项目依赖并根据这些依赖自动装配相应的Bean,从而解放开发者从繁琐的配置工作中解脱出来,专注于业务逻辑实现。
2972 0
|
12月前
|
Java Spring
Spring Boot配置的优先级?
在Spring Boot项目中,配置可通过配置文件和外部配置实现。支持的配置文件包括application.properties、application.yml和application.yaml,优先级依次降低。外部配置常用方式有Java系统属性(如-Dserver.port=9001)和命令行参数(如--server.port=10010),其中命令行参数优先级高于系统属性。整体优先级顺序为:命令行参数 > Java系统属性 > application.properties > application.yml > application.yaml。
1356 0
|
9月前
|
前端开发 Java 应用服务中间件
《深入理解Spring》 Spring Boot——约定优于配置的革命者
Spring Boot基于“约定优于配置”理念,通过自动配置、起步依赖、嵌入式容器和Actuator四大特性,简化Spring应用的开发与部署,提升效率,降低门槛,成为现代Java开发的事实标准。
|
10月前
|
缓存 Java 应用服务中间件
Spring Boot配置优化:Tomcat+数据库+缓存+日志,全场景教程
本文详解Spring Boot十大核心配置优化技巧,涵盖Tomcat连接池、数据库连接池、Jackson时区、日志管理、缓存策略、异步线程池等关键配置,结合代码示例与通俗解释,助你轻松掌握高并发场景下的性能调优方法,适用于实际项目落地。
1768 5
|
10月前
|
传感器 Java 数据库
探索Spring Boot的@Conditional注解的上下文配置
Spring Boot 的 `@Conditional` 注解可根据不同条件动态控制 Bean 的加载,提升应用的灵活性与可配置性。本文深入解析其用法与优势,并结合实例展示如何通过自定义条件类实现环境适配的智能配置。
535 0
探索Spring Boot的@Conditional注解的上下文配置
|
11月前
|
安全 算法 Java
在Spring Boot中应用Jasypt以加密配置信息。
通过以上步骤,可以在Spring Boot应用中有效地利用Jasypt对配置信息进行加密,这样即使配置文件被泄露,其中的敏感信息也不会直接暴露给攻击者。这是一种在不牺牲操作复杂度的情况下提升应用安全性的简便方法。
1564 10
|
人工智能 安全 Java
Spring Boot yml 配置敏感信息加密
本文介绍了如何在 Spring Boot 项目中使用 Jasypt 实现配置文件加密,包含添加依赖、配置密钥、生成加密值、在配置中使用加密值及验证步骤,并提供了注意事项,确保敏感信息的安全管理。
1667 1
|
SQL XML Java
配置Spring框架以连接SQL Server数据库
最后,需要集成Spring配置到应用中,这通常在 `main`方法或者Spring Boot的应用配置类中通过加载XML配置或使用注解来实现。
797 0

热门文章

最新文章