【问题标题】:How to call interceptor before every Dispatcher servlet in spring web flow?如何在 Spring Web Flow 中的每个 Dispatcher servlet 之前调用拦截器?
【发布时间】:2014-11-25 21:51:31
【问题描述】:

嗨朋友们,我在 Spring Web Flow 中工作,在每个事件之前我想要检查会话是否存在,为此我想要调用拦截器,所以我在此处配置 Web 流中的拦截器时遇到问题,ID 我的 Web 流。

<?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>

【问题讨论】:

  • 问题是什么?虽然我可以猜到你的拦截器没有被解雇。您需要通过设置interceptors 属性在FlowHandlerMapping 中设置它。 &lt;mvc:interceptors /&gt; 将与 &lt;mvc:annotation-driven /&gt; 一起使用。
  • 嗨@M.Deinum 你能解释一下sir.how 吗?
  • @M.Deinum 我已经配置了 AOP,但是我如何调用拦截器先生
  • 设置interceptors 属性有什么不明白的地方? Spring 的HandlerInterceptors 也与 AOP 无关,所以不确定它来自哪里。简而言之,删除 &lt;mvc:interceptors /&gt; 并将 &lt;property name="interceptors"&gt;&lt;bean class="com.pcx.ui.converter.ExecuteTimeInterceptor"/&gt;&lt;/property&gt; 添加到 FlowHandlerMapping bean。

标签: java spring interceptor spring-webflow-2


【解决方案1】:

&lt;mvc:interceptors /&gt; 旨在与&lt;mvc:annotation-driven /&gt; 一起使用,它不适用于常规配置的HandlerMapping bean。对于那些你需要配置他们的interceptors 属性的人。

要解决您的问题,请删除 &lt;mvc:interceptors /&gt; 并将配置添加到 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>

【讨论】:

  • 但是先生,当会话无效时,另一个用户在检查会话时如何注销
  • 我不明白你的问题/评论。
  • 先生关于会话(服务器端会话)的任何想法,当用户登录一侧和另一个用户使用相同的密码和用户名(从另一台机器)登录时,当时第一个用户自动注销每当第二个用户使第一个会话无效时。
  • 如上所述,这是一个不同的问题,与这个问题无关。此外,您似乎正在尝试发明自己的安全框架,我强烈建议您查看支持这种开箱即用的Spring Security
  • sir 表示会话中的拦截器概念错误
猜你喜欢
  • 1970-01-01
  • 2017-10-24
  • 2020-01-21
  • 2012-02-15
  • 1970-01-01
  • 2022-11-30
  • 2022-01-19
  • 1970-01-01
  • 2013-04-10
相关资源
最近更新 更多