SSM的拦截器无效,<mvc:interceptor>标签失效

 <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/publisher/**"/>
            <mvc:exclude-mapping path="/loginPublisher"/>
            <bean class="com.lgq.controller.interceptor.PublisherInterceptor"/>
        </mvc:interceptor>
</mvc:interceptors>

 这种写法下我的拦截器完全失效,就跟没有创建一样

 

 

 

 

 <mvc:interceptors>
    <bean class="com.lgq.controller.interceptor.PublisherInterceptor"/>
        <mvc:interceptor>
            <mvc:mapping path="/publisher/**"/>
            <mvc:exclude-mapping path="/loginPublisher"/>
            <bean class="com.lgq.controller.interceptor.PublisherInterceptor"/>
        </mvc:interceptor>
</mvc:interceptors>

这种情况下我的拦截器成了拦截所有的存在,甚至工件一部署完成就会触发一次

 

这是拦截器的代码

package com.lgq.controller.interceptor;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class PublisherInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object arg2) throws Exception {
        HttpSession session = request.getSession();
        if(session.getAttribute("publisherSession")!=null) {
            System.out.println("登录成功不拦截");
            return true;
        }else {
            System.out.println("拦截后进入登录页面");
            response.sendRedirect(request.getContextPath());
            return false;
        }
    }
}

 

检查下你的这个拦截器有没有被spring配置的扫描器扫描路径时包含进去