依赖

<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就会自动刷新配置

 

相关文章:

  • 2021-11-08
  • 2021-05-15
  • 2021-06-28
  • 2021-12-31
  • 2021-11-08
  • 2021-04-14
  • 2021-12-11
  • 2021-11-12
猜你喜欢
  • 2021-10-11
  • 2022-12-23
  • 2022-01-15
  • 2021-07-19
  • 2022-12-23
  • 2021-08-20
相关资源
相似解决方案