Spring mvc interceptor mapping for web application root

I have an Interceptor configured in my application context that I want to map to the web application root ("/").

<mvc:interceptors> <bean class="com.example.SslInterceptor" /> <mvc:interceptor> <mvc:mapping path="/" /> <mvc:mapping path="/login" /> <bean class="com.example.SslInterceptor" /> </mvc:interceptor> </mvc:interceptors> 

But while the interceptor is called for "/ login", it is not for "/". Please, help

+4
source share
2 answers

Change the interceptor configuration in the xml file of the servlet file as follows:

 <mvc:annotation-driven/> <mvc:default-servlet-handler/> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/**"/> <bean class="de.scrappy.web.TestInterceptor"/> </mvc:interceptor> </mvc:interceptors> 
+3
source

Do you really want to map the root path, or did you mean '/ *'? Anyway, the following configuration works for me using Spring 3.1.1, DispatcherServlet maps to root ('/') in web.xml:

 <mvc:annotation-driven/> <mvc:default-servlet-handler/> <mvc:interceptors> <mvc:interceptor> <mvc:mapping path="/"/> <bean class="de.scrappy.web.TestInterceptor"/> </mvc:interceptor> </mvc:interceptors> 

What version of Spring are you using and what does the Spring DispatcherServlet look like? And note that TestInterceptor implements HandlerInterceptor , I don't know if WebRequestInterceptors handled differently.

0
source

All Articles