上篇文章讲到了我们定义portlet应用级别的spring 配置文件为/WEB-INF/config/envprovisioning-config.xml ,下面我们来看下这个spring配置文件内容:
- <?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:webflow="http://www.springframework.org/schema/webflow-config"
- xsi:schemaLocation="
- http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans.xsd
- http://www.springframework.org/schema/webflow-config
- http://www.springframework.org/schema/webflow-config/spring-webflow-config.xsd">
- <!-- Maps portlet modes to handlers -->
- <bean id="portletModeHandlerMapping" class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
- <property name="portletModeMap">
- <map>
- <entry key="view">
- <bean class="com.walmart.platform.envprovisioning.handlers.EnvProvisionFlowHandler" />
- </entry>
- </map>
- </property>
- <property name="interceptors">
- <list>
- <ref bean="envprovisionhandlerinterceptor"/>
- </list>
- </property>
- </bean>
- <!-- add interceptor to get user and privilege -->
- <bean id="envprovisionhandlerinterceptor" class="com.walmart.platform.envprovisioning.interceptors.EnvProvisionHandlerInterceptor"/>
- <!-- Maps logical view names selected by the url filename controller to .jsp view templates within the /WEB-INF directory -->
- <bean id="internalJspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
- <property name="prefix" value="/WEB-INF/" />
- <property name="suffix" value=".jsp" />
- </bean>
- <!-- Enables FlowHandlers -->
- <bean class="org.springframework.webflow.mvc.portlet.FlowHandlerAdapter">
- <property name="flowExecutor" ref="flowExecutor"/>
- </bean>
- <!-- Executes flows: the central entry point into the Spring Web Flow system -->
- <webflow:flow-executor id="flowExecutor" />
- <!-- The registry of executable flow definitions -->
- <webflow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices">
- <webflow:flow-location path="/WEB-INF/flows/envprovision/envprovision.xml" />
- </webflow:flow-registry>
- <!-- Plugs in Spring's JSR-303 validator adapter -->
- <webflow:flow-builder-services id="flowBuilderServices" development="true" validator="validator" />
- <!-- Bootstraps JSR-303 validation and exposes it through Spring's Validator interface -->
- <bean id="validator" class="org.springframework.validation.beanvalidation.LocalValidatorFactoryBean"/>
- </beans>
这个文件更多的是对spring web flow进行了配置,容我细细道来:
首先在第15-17行,我们portletModeMap,对view Mode ,我们扔给了EnvProvisionFlowHandler类,这就表明,我们让在spring portlet mvc中,我们用EnvProvisionFlowHandler类充当portlet view mode的处理类。 而这个EnvProvisionFlowHandler类是从AbstractFlowHandler继承来的, 所以我们理所当然的使用了Spring WebFlow 的FlowHandler来充当处理器:
- /**
- * this class is the flowHandler
- * When application deployed to container ,the container will read the envprovisioning-config.xml
- * then it will get the instance for this flowHandler ,and the getFlowId() method will identify which flow it will
- * enter into.
- *
- *@author cwang58
- *@created date: Feb 18, 2013
- */
- public class EnvProvisionFlowHandler extends AbstractFlowHandler {
- /**
- * the flowId which identifies the flow which will be handled by this flowHandler
- * since here it returns envprovision ,so it will go to the flow which is describled by flow
- * definition file "envprovision.xml"
- */
- public String getFlowId() {
- return "envprovision";
- }
- }
这个类我们只需要实现一个方法,就是getFlowId(),他用来表示,我们用什么web flow来充当view 模式的处理器, 在这里,返回的是envprovision,所以我们用这个流来充当view模式处理器。
既然得到了flowId之后,我们就去找对应的 web flow.首先必须明白,flow的执行者是由FlowHandlerAdaptor来完成的,所以我们在36-38行,我们定义了一个属性叫flowExecutor来专门用于执行flow.
而flowExecutor会专门使用一个flowRegistry Bean来执行定义在/WEB-INF/flows 下的基于XML的流跳转定义文件,所以我们又在44-46行中显式的给出了流定义XML文件,因为(Convention over Configuration),默认的流定义文件的文件名就是flowId,所以我们很容易找到了前文中返回的envprovision的流Id就对应这里的envprovision.xml文件,所以当portlet view 模式时,就会把控制权交给Spring Web Flow,然后用envprovision.xml中定义的流跳转逻辑来处理view 模式,就这么简单。
下篇文章我们来探讨这个流控制文件。