java - how to intercept all requests in spring REST controllers? -
i have 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 need intercept requests reach them,
i created interceptor example:
http://www.mkyong.com/spring-mvc/spring-mvc-handler-interceptors-example/
but never enters :(
because i'm using annotations, don't have xml define interceptor, i've found set 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 doing wrong or missing something?
so apparently doing wrong can't what,
defining interceptor like:
<mvc:interceptors> <bean class="com.test.controllerinterceptor" /> </mvc:interceptors>
i'm pretty sure can define in pure java, working,
answer found in: http://viralpatel.net/blogs/spring-mvc-interceptor-example/
Comments
Post a Comment