title: Spring MVC Monitor / Watch Every Request
body: <p>Is it possible to monitor every Spring request that comes in?</p>
  
  <p>Something like:</p>
  
  <pre><code>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();
  
      }
  
  }
  </code></pre>
  
  <p>OR Perhaps</p>
  
  <pre><code>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();
  
      }
  
  }
  </code></pre>
  
  <p>I want to monitor every request so I can analyze each and count SQL requests, times, etc., but I need to do it on each request, and for each controller.</p>
  
  <p>It should start right before the controller method is called, and end right after the JSP completes.</p>
  
  <p>I am using SpringMVC 4, Spring Boot, Spring Security, Morphia, etc.</p>
  
  <p>Thanks in advance!</p>