使用自定义Interceptor和mvc:annotation-driven配置自定义拦截器失效问题

注解说明

<mvc:annotation-driven />
主要就是为了Spring MVC来用的,提供Controller请求转发,json自动转换等功能。

失效原因

该注解会自动配置
DefaultAnnotationHandlerMapping与AnnotationMethodHandlerAdapter 两个bean,导致无法指定自定义拦截器。并提供了:数据绑定支持,@NumberFormatannotation支持,@DateTimeFormat支持,@Valid支持,读写XML的支持(JAXB),读写JSON的支持(Jackson)。

修改拦截器配置

<!--<mvc:interceptors>-->
    <!--对所有的请求记性拦截-->
    <!--<bean class="com.iousct.ControllerInterceptor"/>-->
    <!--对特定的请求进行拦截-->
    <!--<mvc:interceptor>-->
      <!--<mvc:mapping path="/**"/>-->
      <!--<bean class="com.ious.aspect.ControllerInterceptor"/>-->
    <!--</mvc:interceptor>-->
  <!--</mvc:interceptors>-->

猜你喜欢

转载自blog.csdn.net/m0_38014270/article/details/87366311