SpringCloud(Finchley) Config自动刷新配置文件

config server

  • 一.创建maven项目,加入依赖
	<!--消息队列-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

        <!--actuator-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    
  • 二.编写启动类
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }

}
        
  • 三.在resoures下创建bootstrap.yml(比application.yml先加载)
spring:
  application:
    name: config-server
  cloud:
    config:
      server:
        git:
          uri: https://github.com/ydoublemm/spring-cloud-config-repo.git
  rabbitmq:
    host: your host address
    port: port (default 5672)
    username: your name
    password: your password


management:
  endpoints:
    web:
      exposure:
        include: "*"
  • 四.启动项目

config client

  • 一.创建maven项目,加入依赖
	<!--消息队列-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
        </dependency>

        <!--actuator-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    
  • 二.编写启动类
@SpringBootApplication
public class ConfigClientApplication
{
   public static void main( String[] args ) {
       SpringApplication.run(ConfigClientApplication.class, args);
   }


}
  • 三.在resoures下创建bootstrap.yml(比application.yml先加载)
spring:
  application:
    name: application    # 对应config server所获取的配置文件的{application}
  cloud:
    config:
      discovery:
        enabled: true
        service-id: CONFIG-SERVER
      profile: dev            # profile对应config server所获取的配置文件中的{profile}

management:
  endpoints:
    web:
      exposure:
        include: bus-refresh
  • 创建application.yml
spring:
  rabbitmq:
   host: your host address
   port: port (default 5672)
   username: your name
   password: your password
  • 四.启动项目
    在git上修该配置后,打开cmd
    输入 curl -X POST “localhost:8080/actuator/bus-refresh”
    就能刷新配置了
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值