当前位置: 首页 > news >正文

Springcloud-配置中心config

   一、添加依赖
<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-config-server</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>
  二、添加注解@EnableConfigServer
@SpringBootApplication
@EnableConfigServer
public class MainApplicationCenter3344 {public static void main(String[] args) {SpringApplication.run(MainApplicationCenter3344.class, args);}
}
  三、添加配置
server:port: 3344spring:application:name:  cloud-config-center #注册进Eureka服务器的微服务名cloud:config:server:git:uri: https://github.com/djftjfs/springcloud-config.git #GitHub上面的git仓库名字####搜索目录search-paths:- springcloud-configusername: xxxpassword: xxx####读取分支label: master#服务注册到eureka地址
eureka:client:service-url:defaultZone: http://localhost:7001/eureka

  四、测试http://config-3344.com:3344/master/config-dev.yml

  五、配置读取规则

    label : 分支名 ; application : 服务名 ; profile : 环境(dev/test/prod)

   /{label}/{application}-{profile}.yml

  eg:http://config-3344.com:3344/master/config-dev.yml

 /{application}-{profile}.yml

 eg:http://config-3344.com:3344/config-dev.yml

 /{application}/{profile}/{label}

 eg:http://config-3344.com:3344/config/dev/master

  四、客户端配置

   1、添加依赖

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

   2、创建bootstrap.yml 配置文件

server:port: 3355spring:application:name: config-clientcloud:#Config客户端配置config:label: master #分支名称name: config #配置文件名称profile: dev #读取后缀名称   上述3个综合:master分支上config-dev.yml的配置文件被读取http://config-3344.com:3344/master/config-dev.ymluri: http://localhost:3344 #配置中心地址k#服务注册到eureka地址
eureka:client:service-url:defaultZone: http://localhost:7001/eureka
  五、动态刷新(手动)

        1、在客户端模块添加依赖

 <dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-actuator</artifactId></dependency>

      2、在bootstrap.yml 文件添加如下内容

# 暴露监控端点
management:endpoints:web:exposure:include: "*"

     3、在业务类上添加@RefreshScope

@RestController
@RefreshScope
public class ConfigClientController
{@Value("${config.info}")private String configInfo;@GetMapping("/configInfo")public String getConfigInfo(){return configInfo;}
}

      4、手动刷新(必须post)

      执行 curl -X POST "http://localhost:3355/actuator/refresh"

  六、动态刷新(自动)

      1、在之前基础上在服务端和客户端上添加依赖

<!--添加消息总线RabbitMQ支持--><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-bus-amqp</artifactId></dependency>

      2、服务端添加配置

#rabbitmq相关配置rabbitmq:host: 192.168.xxx.165port: 5672username: adminpassword: 123##rabbitmq相关配置,暴露bus刷新配置的端点
management:endpoints: #暴露bus刷新配置的端点web:exposure:include: 'bus-refresh'

     3、客户端只需添加RabbitMQIP相关配置即可

     4、当在git端修改完配置之后,只需在服务端执行curl -X POST "http://localhost:3344/actuator/bus-refresh" 即可刷新全部客户端

  七、精确刷新

       只需在上面通知上添加服务注册名及端口号即可

       curl -X POST "http://localhost:3344/actuator/bus-refresh/config-client:3355"

http://www.lryc.cn/news/8904.html

相关文章:

  • [项目篇] 音乐播放器开发报告
  • Spring Cloud Alibaba--gateway微服务详解之网关(二)
  • Zynq非VDMA方案实现视频3帧缓存输出,无需SDK配置,提供工程源码和技术支持
  • 血液透析过滤芯气密性检测装置中的高精度多段压力控制解决方案
  • PDF加密如何批量解除?快来了解下这个方法
  • C++——哈希4|布隆过滤器
  • python冒号的用法总结
  • 面试题整理
  • C语言深度解剖-关键字(7)
  • 利用JavaScript编写Python内置函数查询工具
  • 【MySQL进阶】SQL优化
  • 最新版海豚调度dolphinscheduler-3.1.3配置windows本地开发环境
  • csv文件完整操作总结
  • 时间序列预测--基于CNN的股价预测(Matlab代码实现)
  • Dubbo与Spring Cloud优缺点分析(文档学习个人理解)
  • 单元测试工具——JUnit的使用
  • Linux_基本权限
  • 3、JavaScript面试题
  • YUV图像
  • .net6API使用AutoMapper和DTO
  • IO知识整理
  • 【正点原子FPGA连载】第十三章QSPI Flash读写测试实验 摘自【正点原子】DFZU2EG_4EV MPSoC之嵌入式Vitis开发指南
  • 深入理解mysql的内核查询成本计算
  • LeetCode 141. 环形链表
  • git提交
  • Java中常见的编码集问题
  • 数据结构与算法(Java版) | 就让我们来看看几个实际编程中遇到的问题吧!
  • 【C++算法】dfs深度优先搜索(上) ——【全面深度剖析+经典例题展示】
  • 总结高频率Vue面试题
  • IP协议详解