2014-10-20 19 views
0

我試圖將查詢參數傳遞給運行狀況端點。這可能嗎? 例如,http://localhost/health?id=asdfasdf如何訪問Health端點的查詢參數?

我想訪問health()方法中的id。

@Override 
public Health health() { 
    //access id here. 
} 

感謝,

傑裏

+0

是的。有可能的。 – 2014-10-20 16:21:36

+0

穆罕默德,謝謝你確認這是可能的,但我的問題是如何。 – jerrylam 2014-10-20 17:07:46

回答

1

一個Spring啓動端點設計通過許多不同的技術暴露給客戶。例如,HTTP和JMX都支持開箱即用。這意味着在端點中使用特定於HTTP的內容並不是一個好主意。

也就是說,如果你真的提供HealthIndicator這是特定的HTTP你應該能夠使用Spring的RequestContextHolder獲得ServletRequestAttributes實例保持當前請求。從那裏您可以訪問HttpServletRequest並致電getQueryString()

String queryString = (((ServletRequestAttributes) RequestContextHolder 
      .getRequestAttributes()).getRequest().getQueryString()); 
+0

謝謝安迪!我正在嘗試它。 – jerrylam 2014-10-20 17:27:53