如何在spring web流程中的每个Dispatcher servlet之前调用拦截器?

时间:2014-10-01 05:49:35

标签: java spring interceptor spring-webflow-2

嗨朋友我正在春季网络流程中工作会话,在每个事件之前我想检查会话是否存在我想要调用拦截器,所以我有问题在这里配置web流程中的拦截器id我的web流程。< / p>

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:faces="http://www.springframework.org/schema/faces"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd">


    <faces:resources />




    <context:annotation-config />
    <context:component-scan base-package="com.pcx.interceptor.check" />
    <context:component-scan base-package="com.pcx.ui.converter" />
    <mvc:interceptors>
        <bean class="com.pcx.ui.converter.ExecuteTimeInterceptor" />
    </mvc:interceptors>




    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="order" value="1" />
        <property name="flowRegistry" ref="flowRegistry" />
        <property name="defaultHandler">
            <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
        </property>
    </bean>

    <!-- Maps logical view names to Facelet templates in /WEB-INF (e.g. 'search' 
        to '/WEB-INF/search.xhtml' -->
    <bean id="faceletsViewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
        <property name="prefix" value="/WEB-INF/" />
        <property name="suffix" value=".xhtml" />
    </bean>


    <!-- Dispatches requests mapped to org.springframework.web.servlet.mvc.Controller 
        implementations -->
    <bean id="sssssssss"
        class="org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter" />

    <!-- Dispatches requests mapped to flows to FlowHandler implementations -->
    <bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor" />
    </bean>

</beans>

1 个答案:

答案 0 :(得分:0)

<mvc:interceptors />旨在与<mvc:annotation-driven />一起使用,它不适用于常规配置的HandlerMapping bean。对于那些您需要配置其interceptors属性的人。

要解决您的问题,请删除<mvc:interceptors />并将配置添加到FlowHandlerMapping bean。

<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
    <property name="order" value="1" />
    <property name="flowRegistry" ref="flowRegistry" />
    <property name="interceptors">
        <bean class="com.pcx.ui.converter.ExecuteTimeInterceptor"/>
    </property>
    <property name="defaultHandler">
        <bean class="org.springframework.web.servlet.mvc.UrlFilenameViewController" />
    </property>
</bean>