spring mvc 配置 拦截器不起作用

applicationContext.xml 配置

<context:component-scan base-package="com.shdy">
        <!--<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>-->
    </context:component-scan>


<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**" />
            <bean class="com.xx.filter.LocalReqInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>


spring-mvc.xml 主要 配置
<!-- 处理该包中的各种spring注解,即将各个注解类交由容器管理 -->
    <context:component-scan base-package="com.shdy.controller" use-default-filters="false">
        <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    </context:component-scan>
<!--<mvc:annotation-driven/>-->
LocalReqInterceptor 就是普通的 implements HandlerInterceptor 的类.
尝试了半天,死活进不去拦截器。 网上说是<mvc:annotation-driven/> 引起的, 换了上述context:component-scan 方式,仍然进不去拦截器。
解决方案:
@Configuration
public class MyConfig extends WebMvcConfigurationSupport {
   //网上说重写addInterceptors方法,但是我这边没有重新,仍然使用xml方式也是起作用的
}

具体原因还需要学习。有大神路过望不吝赐教

参考: https://blog.csdn.net/q790006739/article/details/100691885

https://www.cnblogs.com/feixuefubing/p/9402198.html

 

posted on 2020-01-10 15:03  远方的人  阅读(1141)  评论(0编辑  收藏  举报

导航