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