是否有可能監視每個到來的Spring請求?Spring MVC監視器/監視每個請求
喜歡的東西:
public class MySpringWatcher extends SpringSomething{
@Override
public HttpServletResponse watchResponse(HttpServletRequest request){
// Starts a timer and counter for analyzing each request made
MyTimerCounter timerCounter = new MyTimerCounter(request);
//Do the request, process Java and JSTL Code
request.doSomething();
// Mark complete and then log results
timerCounter.stop();
}
}
或許
public class MySpringWatcher extends SpringSomething{
MyTimerCounter activeRequest;
@Override
public SpringResponse beforeRequest(HttpServletRequest request){
// Starts a timer and counter for analyzing each request made
activeRequest = new MyTimerCounter(request);
}
@Override
public SpringResponse afterRequest(HttpServletRequest request, HttpServletResponse response){
// Mark complete and then log results
activeRequest.stop();
}
}
我想監控每一個要求,所以我可以分析每個和計數SQL請求,時間等,但我需要做的每個請求和每個控制器。
它應該在調用controller方法之前開始,並在JSP完成後立即結束。
我用SpringMVC使用4,春季啓動,春季安全,嗎啡等
提前感謝!
你可以用過濾器來做到這一點。 – 2015-02-06 18:32:31
謝謝!所以我只是創建了一個'MySpringWatcher'的bean來擴展'javax.servlet.Filter',一切都應該工作? – Nitroware 2015-02-06 18:37:44
我確實嘗試了這一點,但是我必須這樣做,因爲它運行這個命令內部的方法,如每個請求1000次,我只是不知道如何讓它工作。下面的答案真的有幫助 – Nitroware 2015-02-06 20:47:04