In Spring MVC configure the interceptor does not work
spring mvc part of the configuration file
1 <! - start the drive mvc annotation -> 2 <mvc: Annotation-Driven /> . 3 <- - static resource processing!> . 4 <mvc: default -servlet-Handler /> . 5 . 6 <- background! access blocker -> . 7 <MVC: interceptors> . 8 <MVC: interceptor> . 9 <MVC: Mapping path = "/ **" /> 10 <MVC:-Mapping the exclude path = "/ System / Login" /> . 11 <MVC:-Mapping the exclude path = "/ System / get_cpacha" /> 12 is <MVC:-Mapping the exclude path = "/ H-UI / **" /> 13 is <MVC: exclude-mapping path="/easyui/**"/> 14 <bean class="cn.fereli.interceptor.LoginInterceptor"></bean> 15 </mvc:interceptor> 16 </mvc:interceptors> 17 18 <!-- 3.视图的解析器--> 19 <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 20 <property name="prefix" value="/WEB-INF/views/"></property> 21 <property name="suffix" value=".jsp"></property> 22 </bean>
Some say that the Internet is because the configuration of the spring-mvc.xml file
<mvc: annotation-driven />导致拦截器不起作用,因为在这个标签中默认有一个拦截器《
sentence will in fact it has registered a DefaultAnnotationHandlerMapping, and priority in the back of your own registered within it not high, so they will not call you to register interceptors .
Since <mvc: annotation-driven /> interceptors higher priority, so you configure your view resolver when his priority will be to improve
1 <- - backstage access blocker!> 2 <MVC: interceptors> 3 <-! Here the full name of the class declaration interceptors good result solved the problem -> 4 <bean class = "CN. fereli.interceptor.LoginInterceptor "/> . 5 <MVC: Interceptor> . 6 <MVC: Mapping path =" / ** "/> . 7 <MVC:-Mapping the exclude path =" / System / Login "/> . 8 <MVC: the exclude path = -mapping "/ System / get_cpacha" /> . 9 <MVC:-Mapping the exclude path = "/ H-UI / **" /> 10 <MVC:-Mapping the exclude path = "/ easyui / **" /> 11 <bean class="cn.fereli.interceptor.LoginInterceptor"></bean> 12 </mvc:interceptor> 13 </mvc:interceptors>