学习springcloud bus+springcloud config实现刷新配置
依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency>
暴露刷新配置的接口,在yml中配置
management: endpoints: web: exposure: #暴露bus-refresh节点,通过此节点刷新配置 include: '*'
添加注解
@RefreshScope
@RestController @RefreshScope public class TestController { @Value("${girl}") private String girl; @RequestMapping("/msg") public String show(){ System.out.println(girl); return girl;
}
}
码云上的配置文件
server: port: 8763 eureka: client: service-url: defaultZone: http://127.0.0.1:8761/eureka/ spring: application: name: product-server girl: duanyanli
修改配置文件后中的girl熟悉后,访问
http://localhost:8763/actuator/bus-refresh就会自动刷新配置