最近由於集團項目架構太老了,然後全國都在調用,沒辦法,老的流程還得保留,經商量,決定吧框架新搭建一套,老框架採用spring2,0webflow是1.0
新框架採用的springmvc+mybais架構.spring採用的4.2.2版本webflow採用的2.4版本的,但是這是個坑,2.4的webflow跟之前的用法很多地方做了改變,
而且網上好多都是在講述1.0的用法,關於webflow2.4的屈指可數,而且有的也是簡單的配置了一下流程,.
無奈自己研究,看源碼 ,然後猜着去嘗試,
首先看下login.xml的配置
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.0.xsd">
<!-- .doExecute(flowRequestContext) -->
<action-state id="initialFlowSetup">
<evaluate expression="initialFlowSetupAction"/>
<transition on="submit" to="submit" />
<transition on="createOneTimePassword" to="createOneTimePassword" />
<transition on="viewLoginForm" to="viewLoginForm" />
<transition on="warn" to="showWarningView" />
<transition on="error" to="viewLoginForm" />
<transition on="gateway" to="redirectView" />
<transition on="viewGenericLoginSuccess" to="viewGenericLoginSuccess" />
<transition on="redirect" to="redirectView" />
</action-state>
<view-state id="viewLoginForm" view="casLoginView">
<on-render>
<!-這是一個表達式,一定要指明你的方法名.並且要傳參,不要寫on-start->
<evaluate expression="authenticationViaFormAction.setupForm(flowRequestContext)" />
<evaluate expression="authenticationViaFormAction.referenceData(flowRequestContext)" />
</on-render>
<transition on="submit" to="bindAndValidate" />
</view-state>
</flow>
剛開始配置的時候一直卡在on-start哪裏不知道怎麼轉到action-start
後來也是大膽的嘗試,將on-start直接幹掉.你媽竟然好了.
spring-mvc.xml配置,此處爲springmvc與webflow整合之重點
<?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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-4.2.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.2.xsd
http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">
<bean id="casPropertyPlaceholderConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="classpath:uam.properties"></property>
</bean>
<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">
<property name="supportedMediaTypes">
<list>
<value>text/html;charset=UTF-8</value>
</list>
</property>
</bean>
<!-我的頁面都是通過在properties文件中取得的路徑,所以這裏的的視圖解析器我配置的不大一樣->
<bean id="viewResolver"
class="org.springframework.web.servlet.view.ResourceBundleViewResolver"
p:order="0">
<property name="basenames">
<list>
<value>${uam.viewResolver.basename}</value>
<value>protocol_views</value>
</list>
</property>
</bean>
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" />
<!-- webflow配置 -->
<bean name="flowController" class="org.springframework.webflow.mvc.servlet.FlowController">
<property name="flowExecutor" ref="flowExecutor"/>
</bean>
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<!-此處有坑.我不加後綴的話此處攔截不到->
<prop key="/login.do">flowController</prop>
</props>
</property>
</bean>
<webflow:flow-executor id="flowExecutor" />
<webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
<webflow:flow-location path="/WEB-INF/login-webflow.xml" id="login" />
</webflow:flow-registry>
<webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" />
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
<property name="viewResolvers" ref="viewResolver" />
</bean>
</beans>
最後還是你媽報錯,發現原來webflow中可以獲取request和response現在2.4的已經略去此功能,於是採用filter+threadLocal的方式獲取
filter和ThreadLocal工具類的下載地址爲:
http://download.csdn.net/download/qq_38665235/9970336
http://download.csdn.net/download/qq_38665235/9970328
歡迎轉載,請註明出處
http://blog.csdn.net/qq_38665235/article/details/77895936