springcloud系统全局配置与消息总件bus

在git上创建仓库,把配置文件上传到里面
创建配置中心服务
在服务里创建配置文件application.properties

server.port=12000
spring.application.name=cloud-config
spring.cloud.config.server.git.uri=写上git地址
spring.rabbitmq.host=localhost
#暴露触发消息总线的地址
management.endpoints.web.exposure.include=bus-refresh

导入依赖

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

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

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
        </dependency>

入口类加上注解

@EnableConfigServer

这样服务端就完成了
接着客户端
创建文件
bootstrap.properties

#对应git里的master分支的eureka-dev.properties文件
spring.cloud.config.name=eureka
spring.cloud.config.profile=dev
spring.cloud.config.label=master
spring.cloud.config.uri=http://127.0.0.1:12000

添加依赖

 		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-bus</artifactId>
        </dependency>
        
<!--        依赖于消息队列,由于使用的是rabbitmq,导入rabbitmq相关依赖-->

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-stream-binder-rabbit</artifactId>
        </dependency>

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

还要确保git中的配置文件里加上了引入了mq

spring.rabbitmq.host=localhost

这样改完配置文件后,用postman调用一下如下地址,记得要是post请求

http://localhost:12000/actuator/bus-refresh

这样修改springboot相关的如mysql等配置就生效了
如果是自定义配置,要在调用的controller加上@RefreshScope注解

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值