server端配置

POM文件

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>

配置文件

application.yml

server:
port: 8251

spring:
application:
name: config-server-bus
cloud:
config:
server:
git:
username: git userName
password: gitPassword
uri:git Url
search-paths: /spring-cloud-config
default-label: spring-cloud-config
bus:
trace:
enabled: true # 启用日志跟踪
rabbitmq: # rabbitmq的配置信息
host: localhost
port: 5672
username: guest
password: guest

management: # 管理端信息
endpoints:
web:
exposure:
include: bus-env,bus-refresh # 暴露端点
endpoint:
health:
show-details: always # 日志显示时机

client端配置

POM文件

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bus-amqp</artifactId>
</dependency>

配置文件

bootstrap.yml

server:
port: 8081

spring:
rabbitmq: # Rabbit Mq 配置信息
host: localhost
port: 5672
username: guest
password: guest
profiles:
active: dev # 启动项目加载的配置文件类型
application:
name: config
cloud:
config:
uri: http://localhost:8251 # 配置服务器地址
name: ${spring.application.name} # 服务名称
profile: ${spring.profiles.active} # 那个类型的配置为文件 文件类型分为 dev test prod
bus:
trace:
enabled: true
management:
endpoints:
web:
exposure:
include: bus-env,bus-refresh
endpoint:
health:
show-details: always
refresh:
enabled: true

原来代码需要修改的

需要在原来的组件类上加该注解@RefreshScope表示这个类是刷新作用域,其他注解保持不变。

组件类定义:使用了类级注解@RestController@Controller@Service@Repository@Component@Configuration的类

注意:服务端和客户端都需要依赖amqp的依赖。

Spring Cloud Config 使用Bus的动态配置中心的更多相关文章

  1. Spring Cloud Config、Apollo、Nacos配置中心选型及对比

    Spring Cloud Config.Apollo.Nacos配置中心选型及对比 1.Nacos 1.1 Nacos主要提供以下四大功能 2.Spring Cloud Config 3.Apollo ...

  2. Spring cloud config client获取不到配置中心的配置

    Spring cloud client在配置的时候,配置文件要用 bootstrap.properties 贴几个说明的链接.但是觉得说的依然不够详细,得空详查. 链接1 链接2 链接3 原文地址:h ...

  3. 9.Spring Cloud Config统一管理微服务配置

    Spring Cloud Config统一管理微服务配置 9.1. 为什么要统一管理微服务配置 9.2. Spring Cloud Config简介 Spring Cloud Config为分布式系统 ...

  4. spring boot 2.0.3+spring cloud (Finchley)6、配置中心Spring Cloud Config

    https://www.cnblogs.com/cralor/p/9239976.html Spring Cloud Config 是用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持, ...

  5. Spring Cloud学习笔记【九】配置中心Spring Cloud Config

    Spring Cloud Config 是 Spring Cloud 团队创建的一个全新项目,用来为分布式系统中的基础设施和微服务应用提供集中化的外部配置支持,它分为服务端与客户端两个部分.其中服务端 ...

  6. 一起来学Spring Cloud | 第七章:分布式配置中心(Spring Cloud Config)

    上一章节,我们讲解了服务网关zuul,本章节我们从git和本地两种存储配置信息的方式来讲解springcloud的分布式配置中心-Spring Cloud Config. 一.Spring Cloud ...

  7. Spring Cloud学习笔记【十】配置中心(消息驱动刷新配置)

    上一篇中讲到,如果需要客户端获取到最新的配置信息需要执行refresh,我们可以利用 Webhook 的机制每次提交代码发送请求来刷新客户端,当客户端越来越多的时候,需要每个客户端都执行一遍,这种方案 ...

  8. Spring Cloud Alibaba 整合 Nacos 实现服务配置中心

    在之前的文章 <Nacos 本地单机版部署步骤和使用> 中,大家应该了解了 Nacos 是什么?其中 Nacos 提供了动态配置服务功能 一.Nacos 动态配置服务是什么? 官方是这么说 ...

  9. Spring Cloud系列(六):配置中心

    在使用Spring Boot的时候,我们往往会在application.properties配置文件中写一些值,供应用使用,这样做的好处是可以在代码中引用这些值,当这些值需要作出修改的时候,可以直接修 ...

随机推荐

  1. 常见的页面效果,相关的js代码

    1.焦点图 $(document).ready(function(){ var i=0; var autoChange= setInterval(function(){ if(i<$(" ...

  2. SDUT OJ 2892 A (字典树问题-输出出现次数最多的字符串的出现次数,60ms卡时间,指针+最后运行完释放内存)

    A Time Limit: 60ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 给出n(1<= n && n <= 2*10^6)个字 ...

  3. YTU 2425: C语言习题 输出月份

    2425: C语言习题 输出月份 时间限制: 1 Sec  内存限制: 128 MB 提交: 476  解决: 287 题目描述 编写一程序,输入月份号,输出该月的英文月名.例如,输入3,则输出Mar ...

  4. android 一个TextView设置多种颜色

    时候一个文本框为了强调内容需要显示不同颜色,用以下代码可以轻松实现 方法一:(适用于颜色变化多的情况)   //为文本框设置多种颜色 textView=(TextView)findViewById(R ...

  5. hdu acm 2191 悼念512汶川大地震遇难同胞——珍惜现在,感恩生活

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191 题目意思:有 资金 n 和 m 种类型的大米,对第 i 种类型的大米,价格.数量.袋数分别是: ...

  6. Hadoop的jobhistoryserver配置

    配置mapred-site.xml <configuration> <property> <name>mapreduce.framework.name</na ...

  7. js 购物车中,多件商品数量加减效果修改,实现总价随数量加减改变

    <!DOCTYPE html> <html> <head> <meta charset=UTF-8 /> <title>无标题文档</ ...

  8. iOS NSInteger/NSUInteger与int/unsigned int、long/unsigned long之间的区别!

    在iOS开发中经常使用NSInteger和NSUInteger,而在其他的类似于C++的语言中,我们经常使用的是int.unsigned int.我们知道iOS也可以使用g++编译器,那么它们之间是否 ...

  9. [SHOI 2009] 会场预约

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2028 [算法] 直接用std :: set维护即可 时间复杂度 : O(NlogN) ...

  10. [yii2]Module的Namespace和控制器位置

    namespace和目录对应,否则无法找到控制器类,module文件在根路径 使用gii生成Module为\app\admin,那么 namespace app; class admin extend ...