title: how to intercept all requests in spring REST controllers?
body: <p>I have a bunch of controllers like:</p>
  
  <pre><code>@RestController
  public class AreaController {
      @RequestMapping(value = "/area", method = RequestMethod.GET)
      public @ResponseBody ResponseEntity&lt;Area&gt; get(@RequestParam(value = "id", required = true) Serializable id) { ... }
  }
  </code></pre>
  
  <p>and I need to intercept all the requests that reach them,</p>
  
  <p>I created an interceptor like this example:</p>
  
  <p><a href="http://www.mkyong.com/spring-mvc/spring-mvc-handler-interceptors-example/" rel="noreferrer">http://www.mkyong.com/spring-mvc/spring-mvc-handler-interceptors-example/</a></p>
  
  <p>but it never enters :(</p>
  
  <p>because I'm using only annotations, i don't have a XML to define the interceptor,
  what I've found its to set it like this:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "com.test.app")
  public class AppConfig extends WebMvcConfigurerAdapter {
  
      @Bean
      public ControllerInterceptor getControllerInterceptor() {
          ControllerInterceptor c = new ControllerInterceptor();
          return c;
      }
  
      @Override
      public void addInterceptors(InterceptorRegistry registry) {
          registry.addInterceptor(getControllerInterceptor());
          super.addInterceptors(registry);
      }
  
  }
  </code></pre>
  
  <p>what am i doing wrong or am i missing something?</p>