springcloud config服务端开发

本文探讨了如何使用Spring Cloud Config Server与Git协同,管理应用配置,包括依赖管理、config注解应用、配置文件版本控制和通过MQ实现配置推送。重点介绍了如何配置Git地址,以及不同环境下的配置请求方式和Kafka/MQ的应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、pom.xml依赖

dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-config-server</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-kafka</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.boot</groupId>
   <artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

2、config注解

3、配置git地址(配置文件存放git位置)

下图uri为路径

  • application: 表示微服务名称,即配置的spring.application.name
  • profile: 表示当前的环境,local、feature、dev、test、prod
  • label: 表示git仓库分支,feature、develop、test、master,当然默认的话是master
  • 在启动Config Server后去请求获取Git Repo中的配置文件时有以下几种请求形式。

    1

    2

    3

    4

    5

    /{application}/{profile}[/{label}]

    /{application}-{profile}.yml

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

    /{application}-{profile}.properties

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

4、设置kafka或MQ(config通过MQ通知客户端配置文件更改)

spring.config.stream.default-binder: kafka
spring.kafka.bootstrap-servers: - 139.159.157.32:9092

浏览器输入ip:port/配置文件名字测试是否成功。

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值