SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-001- 配置SpringFlow(flow-executor、flow-registry、FlowHandlerMapping、FlowHandlerAdapter)
一、
1.Wiring a flow executor
<flow:flow-executor id="flowExecutor" />
Although the flow executor is responsible for creating and executing flows, it’s not responsible for loading flow definitions. That responsibility falls to a flow registry,which you’ll create next.
2.Configuring a flow registry
A flow registry’s job is to load flow definitions and make them available to the flow executor.
(1)通配符<flow:flow-location-pattern>
<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows">
<flow:flow-location-pattern value="*-flow.xml" />
</flow:flow-registry>
As declared here, the flow registry will look for flow definitions under the / WEB-INF /flows directory, as specified in the base-path attribute. Per the <flow:flow-location-pattern> element, any XML file whose name ends with -flow.xml will
be considered a flow definition.
All flows are referred to by their ID s.Using <flow:flow-location-pattern> as you have, the flow ID is the directory
path relative to the base-path —or the part of the path represented with the double asterisk
或者
<!-- The registry of executable flow definitions -->
<flow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows">
<flow:flow-location-pattern value="/**/*-flow.xml" />
</flow:flow-registry>
(2)明确位置 <flow:flow-location>
<flow:flow-registry id="flowRegistry">
<flow:flow-location path="/WEB-INF/flows/springpizza.xml" />
</flow:flow-registry>
When configured this way, the flow’s ID is derived from the base name of the flow definition file, springpizza in this case.
或者指定id
<flow:flow-registry id="flowRegistry">
<flow:flow-location id="pizza" path="/WEB-INF/flows/springpizza.xml" />
</flow:flow-registry>
3.Handling flow requests
(1)装配FlowHandlerMapping,告诉DispatcherServlet,把flow交给它处理
DispatcherServlet typically dispatches requests to controllers. But for flows, you need a FlowHandlerMapping to help DispatcherServlet know that it should send flow requests to Spring Web Flow
<!--Maps request paths to flows in the flowRegistry-->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry" />
</bean>
As you can see, the FlowHandlerMapping is wired with a reference to the flow registry so it knows when a request’s URL maps to a flow. For example, if you have a flow whose ID is pizza , then FlowHandlerMapping will know to map a request to that flow if the request’s URL pattern (relative to the application context path) is /pizza.
(2)装配FlowHandlerAdapter
Whereas the FlowHandlerMapping ’s job is to direct flow requests to Spring Web Flow, it’s the job of a FlowHandlerAdapter to answer that call. A FlowHandlerAdapter is equivalent to a Spring MVC controller in that it handles requests coming in for a flow and processes those requests.
<!--
Dispatches requests mapped to flows to FlowHandler implementations
-->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
</bean>
This handler adapter is the bridge between DispatcherServlet and Spring Web Flow.It handles flow requests and manipulates the flow based on those requests. Here, it’s wired with a reference to the flow executor to execute the flows for which it handles requests.
二、所有的配置文件如下,webflow模块不支持java配置,只能用xml配置
1.
2.web.xml
<?xml version="1.0" encoding="ISO-8859-1"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/root-config.xml</param-value>
</context-param> <listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <servlet>
<servlet-name>SpringPizza</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value></param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet> <servlet-mapping>
<servlet-name>SpringPizza</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping> </web-app>
3.root-config.xml
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd"> <import resource="mvc.xml" />
<import resource="flow.xml" />
<import resource="services.xml" />
<import resource="domain.xml" />
<import resource="dataaccess.xml" /> <context:component-scan base-package="com.springinaction.pizza" /> </beans>
4.mvc.xml
<?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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> <mvc:annotation-driven /> <!-- View resolver for the pizza flow, as shown on page 594 -->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean> </beans>
5.flow.xml
<?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:flow="http://www.springframework.org/schema/webflow-config"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/webflow-config
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.3.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:component-scan base-package="com.springinaction.pizza.flow" /> <!-- Executes flows: the entry point into the Spring Web Flow system -->
<flow:flow-executor id="flowExecutor" /> <!-- The registry of executable flow definitions -->
<flow:flow-registry id="flowRegistry"
base-path="/WEB-INF/flows">
<flow:flow-location-pattern value="/**/*-flow.xml" />
</flow:flow-registry> <!--Maps request paths to flows in the flowRegistry-->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
<property name="flowRegistry" ref="flowRegistry" />
</bean> <!--
Dispatches requests mapped to flows to FlowHandler implementations
-->
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
<property name="flowExecutor" ref="flowExecutor" />
</bean> </beans>
6.services.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd"> <bean id="pricingEngine"
class="com.springinaction.pizza.service.PricingEngineImpl" /> <!--
<lang:groovy id="pricingEngineGroovy"
script-source="classpath:scripts/PricingEngineImpl.groovy" />
--> <bean id="customerService"
class="com.springinaction.pizza.service.CustomerServiceImpl" /> <!-- Payment processing bean, as discussed on page 606 -->
<bean id="paymentProcessor"
class="com.springinaction.pizza.service.PaymentProcessor" /> <bean id="orderService"
class="com.springinaction.pizza.service.OrderServiceImpl" /> </beans>
7.domain.xml
<?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:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <context:spring-configured /> <bean id="order" class="com.springinaction.pizza.domain.Order" abstract="true">
<property name="pricingEngine" ref="pricingEngine" />
</bean> </beans>
8.dataaccess.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
</beans>
SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-001- 配置SpringFlow(flow-executor、flow-registry、FlowHandlerMapping、FlowHandlerAdapter)的更多相关文章
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-002-SpringFlow的组件(state\<transition>\<var>\<set>\<evaluate>)
一. In Spring Web Flow, a flow is defined by three primary elements: states, transitions,and flow dat ...
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-004-Pizza例子的用户流程(flowExecutionKey、_eventId_phoneEntered、flowExecutionUrl )
一. 1. 2. 3.customer-flow.xml 自己定义customer,最后output <?xml version="1.0" encoding="U ...
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-003-Pizza例子的基本流程
一. 1. 2.pizza-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow xml ...
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-007-给flowl加权限控制<secured>
States, transitions, and entire flows can be secured in Spring Web Flow by using the <secured> ...
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-006-Pizza例子的支付流程
一. 1. 2.payment-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flow x ...
- SPRING IN ACTION 第4版笔记-第八章Advanced Spring MVC-005-Pizza例子的订单流程()
一. 1.订单流程定义文件order-flow.xml <?xml version="1.0" encoding="UTF-8"?> <flo ...
- SPRING IN ACTION 第4版笔记-第十一章Persisting data with object-relational mapping-006Spring-Data的运行规则(@EnableJpaRepositories、<jpa:repositories>)
一.JpaRepository 1.要使Spring自动生成实现类的步骤 (1)配置文件xml <?xml version="1.0" encoding="UTF- ...
- SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-003-四种方式获取DataSource
一.概述 1.Spring offers several options for configuring data-source beans in your Spring application, i ...
- SPRING IN ACTION 第4版笔记-第十章Hitting the database with spring and jdbc-001-Spring对原始JDBC的封装
1.spring扩展的jdbc异常 2.Template的运行机制 Spring separates the fixed and variable parts of the data-access p ...
随机推荐
- SharePoint 学习记事(二)
买了一本<sharepoint2010开发高级编程> 据说评价也不高. 搜到如下文章,留着看看:http://book.douban.com/review/5673741/ http:// ...
- 取A表数据,关联B表任意一条数据
表A=================== AID, AName 1 jack 2 mary 3 lily 表B================== BID, AID, BName 1 1 aaa ...
- JavaScript学习笔记(5)——JavaScript语法之数据类型
JavaScript 拥有动态类型.这意味着相同的变量可用作不同的类型: var x // x 为 undefined var x = 6; // x 为数字 var x = "Bill&q ...
- Android笔记之adb命令应用实例1(手机端与PC端socket通讯下)
通过adb和Android通讯需要引用adb相关的组件到项目中,分别为:adb.exe,AdbWinApi.dll,AdbWinUsbApi.dll. 可以在XXX\sdk\platform-tool ...
- CSU-ACM2016暑假集训训练2-DFS(C - Network Saboteur)
C - Network Saboteur Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu ...
- centos coreseek 快速安装
CoreSeek快速安装: 安装前,建议查看:源码包说明README:4.0/4.1版可参考3.2版本安装,步骤相同:如遇到问题,请看详细安装说明. ##下载coreseek:coreseek 3.2 ...
- 重新开始学习c#啦,希望能坚持下去!
过了这么多年,还是感觉自己喜欢C#,喜欢编程,虽然自己什么技术也没有:做的项目也不算是项目:
- 开发APP不搞清楚这20个问题,必然沦为一场灾难
移动经济的高速增长极大刺激了企业和个人的APP开发热情,从卖野山鸡的到卖无人机的,从老大妈到小正太都跃跃欲试,更不要说那些传统企业的信息主管们了. 面对今天如过江之鲫的APP市场,很少有人意识到,移动 ...
- php 用户验证的简单示例
发布:thebaby 来源:net [大 中 小] 本文介绍下,在php中,进行用户登录验证的例子,这个是基于WWW-Authenticate登录验证的实例,有需要的朋友参考下吧. 大家是 ...
- android适应屏幕
生产android手机的厂商多不胜数,造就了android手机的屏幕尺寸也是不计其数.开发者为了使应用在各个品牌,各个型号的手机屏幕上保持一致的用户体验,就需要运用多种使应用的UI能适应不同屏幕尺寸的 ...