我試圖將查詢參數傳遞給運行狀況端點。這可能嗎? 例如,http://localhost/health?id=asdfasdf
如何訪問Health端點的查詢參數?
我想訪問health()方法中的id。
@Override
public Health health() {
//access id here.
}
感謝,
傑裏
我試圖將查詢參數傳遞給運行狀況端點。這可能嗎? 例如,http://localhost/health?id=asdfasdf
如何訪問Health端點的查詢參數?
我想訪問health()方法中的id。
@Override
public Health health() {
//access id here.
}
感謝,
傑裏
一個Spring啓動端點設計通過許多不同的技術暴露給客戶。例如,HTTP和JMX都支持開箱即用。這意味着在端點中使用特定於HTTP的內容並不是一個好主意。
也就是說,如果你真的想提供HealthIndicator
這是特定的HTTP你應該能夠使用Spring的RequestContextHolder
獲得ServletRequestAttributes
實例保持當前請求。從那裏您可以訪問HttpServletRequest
並致電getQueryString()
:
String queryString = (((ServletRequestAttributes) RequestContextHolder
.getRequestAttributes()).getRequest().getQueryString());
謝謝安迪!我正在嘗試它。 – jerrylam 2014-10-20 17:27:53
是的。有可能的。 – 2014-10-20 16:21:36
穆罕默德,謝謝你確認這是可能的,但我的問題是如何。 – jerrylam 2014-10-20 17:07:46