Bus, 事件、消息總線,用於在集羣(例如,配置變化事件)中傳播狀態變化,可與Spring Cloud Config聯合實現熱部署。html
本實例採用rabbitmq實現。spring
下載安裝: http://www.rabbitmq.com/download.html docker
配置用戶名和密碼。segmentfault
在docker部署時,採用官方鏡像,添加環境變量RABBITMQ_DEFAULT_USER = ***,
RABBITMQ_DEFAULT_PASS = ***,
設置用戶名和密碼
具體參見: https://hub.docker.com/_/rabbitmq/
一、pom引入服務器
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>
二、配置文件spa
spring: rabbitmq: host: rabbitmq port: 5672 username: user password: password
三、類文件使用code
@RefreshScope 類文件註解
@Value("${wordConfig.word}") String word; //已注入方式得到值其餘寫法:參見 https://segmentfault.com/a/1190000006226542