永远不会调用spring拦截器

时间:2013-05-14 16:11:18

标签: java spring spring-mvc interceptor

我有以下拦截器:

@Component
public class ExternalLinkInterceptor extends HandlerInterceptorAdapter {

    private static final Logger logger = Logger.getLogger(ExternalLinkInterceptor.class);

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        logger.info("preHandle ~ invoked");
}
}

它应该在请求处理以下控制器方法之前拦截:

@Controller
@PreAuthorize("isAuthenticated()")
@RequestMapping("/assay/process")
public class VariantPrioritizationsController extends AssayBaseController{

    private static final Logger logger = Logger.getLogger(VariantPrioritizationsController.class);
@RequestMapping("/openAnalyticalProjectForAssay")
    public ModelAndView openAnalyticalProjectForAssay(HttpSession session,@RequestParam(value = "analyticalProjId", required=true)String projectId) throws PanDaApplicationException{
    //code 
     }
}

这是spring-servlet.xml中的拦截器声明:

<mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/assay/process/openAnalyticalProjectForAssay*"/>
            <beans:bean class="com.syngenta.panda.web.mvc.interceptor.ExternalLinkInterceptor"/>
        </mvc:interceptor>
    </mvc:interceptors>

现在我的拦截器永远不会被调用,我不知道为什么?!任何帮助

2 个答案:

答案 0 :(得分:4)

请尝试将mvc:mapping路径更新为:

<mvc:mapping path="/assay/process/**" />

答案 1 :(得分:-1)

mvc:interceptor的配置对我来说并不合适。我之前在Spring中使用过locale更改拦截器,它们的配置非常简单:

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor" p:paramName="language"/>
</mvc:interceptors>

此拦截器只是在URL上查找param以更改用户选择的区域设置。

此视频介绍了所有内容的设置,包括语言环境拦截器:

http://pluralsight.com/training/Courses/TableOfContents/springmvc-intro