首先,整合Struts1和Spring很简单:
需要先在 web.xml中 配置listener
然后在 struts-config.xml 中修改action中的type为
org.springframework.web.struts.DelegatingActionProxy
还要加个
<plug-in>
然后在 Spring的配置文件中配置对应的bean
打开Web之后,后端会调用index去执行后续步骤:
Struts-config.xml:
<action path="/index" type="com.fisglobal.base.SecureAction"
unknown="true">
<forward name="secure" path="/customerDashboard.do"
redirect="true" />
<forward name="unsecure" path="/login.do" redirect="true"
/>
</action>
在执行完SecureAction之后,返回unsecure则转到/login.do;依然在Struts-config.xml中:
<action path="/login" type="org.springframework.web.struts.DelegatingActionProxy"
name="actionForm" scope="request"
input="webClient.passmark.login">
<forward
name="customerAuthentication" path="webClient.login" />
<forward
name="customerUsername" path="webClient.passmark.login" />
<forward
name="customerPassword" path="webClient.passmark.password"
/>
<forward name="customerAuthenticationSuccess"
path="/accountList.do" redirect="true" />
</action>
蓝色部分表示Struts1和Spring整合,需要在所有的type中写明蓝色的这个类,表名所有action交给Spring的bean处理,并且需要在Struts-config.xml中配置如下:
<plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property
property="contextConfigLocation" value="/WEB-INF/action-servlet.xml"/>红色表示Spring配置文件
</plug-in>
继续,于是在action-servlet.xml找到bean name为/login的配置:
<bean name="/login" class="com.fisglobal.base.FlowAction">
<property
name="flowExecutor" ref="flowExecutor"/>
<property
name="argumentHandler">
<bean
class="org.springframework.webflow.executor.support.RequestParameterFlowExecutorArgumentHandler">
<property
name="defaultFlowId"><value>login</value></property>
</bean>
</property>
</bean>
很显然绿色部分是一个工作流,传递的参数是login这个flowID,接着我们找到flowExecutor这个配置(还是在action-servlet.xml中):
<bean id="flowExecutor"
class="org.springframework.webflow.config.FlowExecutorFactoryBean">
<property
name="definitionLocator" ref="flowRegistry"/>
<property
name="executionListenerLoader">
<bean
class="org.springframework.webflow.execution.factory.StaticFlowExecutionListenerLoader">
<constructor-arg>
<ref
local="exceptionHandler"/>
</constructor-arg>
</bean>
</property>
<property
name="executionAttributes">
<map>
<entry
key="alwaysRedirectOnPause">
<value
type="java.lang.Boolean">true</value>
</entry>
</map>
</property>
<property
name="conversationManager">
<bean
class="org.springframework.webflow.conversation.impl.SessionBindingConversationManager">
<property
name="maxConversations" value="1"/>
</bean>
</property>
</bean>
草绿色部分为默认配置,不用去管他。接着找到注册工作流的配置,还是在action-servlet.xml中:
<bean id="flowRegistry"
class="org.springframework.webflow.engine.builder.xml.XmlFlowRegistryFactoryBean">
<property
name="documentLoader">
<bean
class="org.springframework.webflow.engine.builder.xml.DefaultDocumentLoader">
<property
name="validating"
value="false"/>
</bean>
</property>
<property
name="flowDefinitions">
<props>
<prop
key="accountCreation">/WEB-INF/flows/account-creation.xml</prop>
<prop
key="accountCreationCustomerAuthentication">/WEB-INF/flows/${authentication}authentication.xml</prop>
<prop
key="login">/WEB-INF/flows/${authentication}authentication.xml</prop>
<prop
key="customerCreation">/WEB-INF/flows/customer-creation.xml</prop>
<prop
key="customerCreationCorporate">/WEB-INF/flows/customer-creation-corporate.xml</prop>
<prop
key="customerCreationPersonal">/WEB-INF/flows/customer-creation-personal.xml</prop>
<prop
key="authKeys">/WEB-INF/flows/passmark-keys.xml</prop>
<prop
key="authChallenges">/WEB-INF/flows/passmark-challenges.xml</prop>
<prop
key="authManagement">/WEB-INF/flows/auth-management.xml</prop>
<prop
key="customerIda">/WEB-INF/flows/customer-ida.xml</prop>
</props>
</property>
</bean>
找到key为login的那一行,找到authentication.xml的工作流配置文件:
<input-mapper>
<mapping source="user"
target="conversationScope.user"/>
<mapping
source="userName"
target="conversationScope.userName"/>
<mapping
source="currentRole"
target="conversationScope.currentRole"/>
<mapping
source="currentRoleUserNumber"
target="conversationScope.currentRoleUserNumber"/>
<mapping
source="putUserIntoSession"
target="conversationScope.putUserIntoSession"/>
<mapping
source="checkCustomerTypeDefined"
target="conversationScope.checkCustomerTypeDefined"/>
</input-mapper>
表示这意味着这个流程希望以一个名为user的对象作为输入。如前所述,当注册流程作为子流程执行时,子流程定义会为将要传递给注册流程的用户对象创建一个输入映射表。这就是这两个流程绑定到一块的方式。