- Mastering Spring 5.0
- Ranga Rao Karanam
- 57字
- 2021-07-02 22:12:17
Mapping HandlerInterceptor to handlers
HandlerInterceptors can be mapped to specific URLs you would want to intercept. The following example shows an example XML context configuration. By default, the interceptor will intercept all handlers (controllers):
<mvc:interceptors>
<bean class="com.mastering.spring.springmvc.
controller.interceptor.HandlerTimeLoggingInterceptor" />
</mvc:interceptors>
We can configure precise URIs to be intercepted. In the following example, all handlers except those with URI mapping starting with /secure/are intercepted:
<mvc:interceptors>
<mapping path="/**"/>
<exclude-mapping path="/secure/**"/>
<bean class="com.mastering.spring.springmvc.
controller.interceptor.HandlerTimeLoggingInterceptor" />
</mvc:interceptors>