springcloud 配置actuator


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

成功!

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM