继续潜水

导航

 

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

成功!

 

posted on 2019-08-16 09:26  继续潜水  阅读(1838)  评论(0编辑  收藏  举报