pom.xml


<!--Spring Boot Actuator,感应服务端变化-->
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
bootstrap.yml
management:
  endpoints:
    web:
      exposure:
        include: refresh,health,info
TestController
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("test")
@RefreshScope
public class TestController {
    @Value("${name.str}")
    private String str ;

    @RequestMapping("hi")
    public String hi(){
        System.out.println(str);
        return  str;
    }
}

调用接口

  http://127.0.0.1:9092/test/hi   返回   55555

修改config端 name.str:6666

刷新接口

  http://127.0.0.1:9092/actuator/refresh

  返回

  [
    "config.client.version",
    "name.str"
  ]

调用接口

  http://127.0.0.1:9092/test/hi   返回   66666

成功!

 

相关文章:

  • 2022-12-23
  • 2021-06-04
  • 2021-12-03
  • 2022-01-04
  • 2021-11-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-08
  • 2021-08-07
  • 2022-01-18
  • 2022-12-23
  • 2021-10-06
  • 2022-02-28
  • 2021-08-11
相关资源
相似解决方案