title: Audit/Log all incoming web requests to @RequestMapping annotated methods
body: <p>Source</p>
  
  <p><a href="http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-handlermapping" rel="nofollow">http://docs.spring.io/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-handlermapping</a></p>
  
  <p>I have Controller classes annotated with @Controller, they have methods annotated with @RequestMapping. <strong>My task is to audit all the web requests received by the Controller classes to @RequestMapping methods</strong>, I am using datatables on UI to send and receive response from controllers. the Audit framework is already in place.</p>
  
  <p>The project is configured in Java Config.</p>
  
  <p>I am not sure how to proceed on getting this done.</p>
  
  <pre><code>// Configure Interceptor
  
  public class WebConfig extends WebMvcConfigurerAdapter {
      @Override
  public void addInterceptors(InterceptorRegistry registry) {
      registry.addInterceptor(new MyInterceptor());
  }
  
  public @Bean
  RequestMappingHandlerMapping requestMappingHandlerMapping() {
      RequestMappingHandlerMapping handlerMapping = new RequestMappingHandlerMapping();
      handlerMapping.setAlwaysUseFullPath(true);
      handlerMapping.setUseSuffixPatternMatch(false);
      return handlerMapping;
    }
  }
  
  //Add Handler
  @Component
  public class MyInterceptor extends HandlerInterceptorAdapter {
  @Inject RequestMappingHandlerMapping requestMappingHandlerMapping;
  public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
          throws Exception {
  // do stuff - ( Does my Audit Code go here? eg: Logger.info("xyz request"))
  return true;
   }
  }
  </code></pre>
  
  <p>I was thinking something like this would work.</p>
  
  <p>Any Suggestions on this, and
  if its easier Using Listener or some other Interceptor, it would be helpful</p>