Reputation: 1044
I'm developing a spring MVC application that uses a filter implementing javax.servlet.Filter
and an Interceptor extending org.springframework.web.servlet.handler.HandlerInterceptorAdapter.
As far as I know, the control flow of Spring MVC is something like this:
DispatcherServlet
.DispatcherServlet
sends it to Interceptor
and the overrided preHandle
method is executed.postHandle
method of interceptor is also overrided Spring executes its code.DispatcherServlet
uses the view resolver and sends the model to view, rendering it.Doing some tests I can see my filter is always executed BEFORE the preHandle
method. It seems to be the first executed thing after DispatcherServlet
. It's ok, but I do not find the reason for this behaviour. Someone with a good explanation?
Thanks!
UPDATE: Possibility: It's because filter is defined in web.xml
(like DispatcherServlet
) so Filter is executed before DispatcherServlet
?
Upvotes: 17
Views: 14673
Reputation: 3320
It's perfectly fine as
Filter's
are part of Servlet specification.
Filters
are called by your Server(tomcat)
. while Interceptors are called by Spring
.
Upvotes: 18