7.springcloud Config配置自动刷新

准备:搭建一个服务注册中心,一个配置中心,和一个获取配置的客户端。

提前安装RabbitMQ官网下载 https://www.rabbitmq.com/install-windows.html

git上准备一个文件用做测试

一、Config-Server(配置中心)配置

1.添加依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-bus-amqp</artifactId>
    </dependency>

2.修改配置文件application.yml文件

server:
  port: 8085
#  servlet:
#    context-path:   #访问项目前缀
spring:
  application:
    name: config-server   #服务注册中心的名称
  cloud:
    config:
      label: master
      server:
        git:
          uri: https://github.com/zhujw0/springCloud-config/
          search-paths: config
  rabbitmq:  #本地环境不需要配置mq,但是需要启动mq,Springboot会自动连接本地mq
    host: localhost
    port: 5672
    username: guest
    password: guest

eureka:
  client:
    service-url:
      defaultZone: http://www.eureka-server.com:1111/eureka/  #对应Eureka-server中的url
  instance:
    hostname: www.client.com
management:  #暴露/bus-refresh接口
  endpoints:
    web:
      exposure:
        include: "*"

# curl -X POST http://www.client.com:8085/actuator/bus-refresh         cmd窗口输入,模拟post请求

3.启动类添加注解  @EnableConfigServer

二、Config Client端配置(测试获取Config-Server服务端获取的git配置)

1.添加依赖

    <dependency>
        <groupId>org.springframework.cloud</groupId>
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值