I have a bunch of controllers like:
@RestController
public class AreaController {
@RequestMapping(value = "/area", method = RequestMethod.GET)
public @ResponseBody ResponseEntity<Area> get(@RequestParam(value = "id", required = true) Serializable id) { ... }
}
and I need to intercept all the requests that reach them,
I created an interceptor like this example:
http://www.mkyong.com/spring-mvc/spring-mvc-handler-interceptors-example/
but it never enters :(
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:
@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);
}
}
what am i doing wrong or am i missing something?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…