Configuring custom interceptors
While servlet filters are a part of the Servlet API and have nothing to do with Spring besides being automatically added in the filter chain --Spring MVC provides us with another way of wrapping web requests: HandlerInterceptor
. According to the documentation, HandlerInterceptor
is just like a filter. Instead of wrapping a request in a nested chain, an interceptor gives us cutaway points at different phases, such as before the request gets handled, after the request has been processed, before the view has been rendered, and at the very end, after the request has been fully completed. It does not let us change anything about the request, but it does let us stop the execution by throwing an exception or returning false if the interceptor logic determines so.
Similar to using filters, Spring MVC comes with a number of premade HandlerInterceptors
. The commonly used ones are LocaleChangeInterceptor
and ThemeChangeInterceptor
; but there are certainly others that...