step 2.0
This commit is contained in:
@@ -34,7 +34,7 @@
|
||||
|
||||
<!-- Enables web flows; responsible for calling the Spring Web Flow system to execute a flow when one is mapped. -->
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
|
||||
<property name="flowExecutor" ref="flowExecutor"/>
|
||||
<property name="flowExecutor" ref="flowExecutor" />
|
||||
</bean>
|
||||
|
||||
<!-- Note: all Spring MVC request HandlerAdapters above must be explicitly registered now that we are now overriding the defaults to plug-in the FlowHandlerAdapter -->
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
|
||||
<%@ page session="false" %>
|
||||
<html>
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
<title>Getting Started with Spring Web Flow: Setting up Web Flow in a Spring Web Application</title>
|
||||
</head>
|
||||
@@ -12,17 +12,100 @@
|
||||
What does the configuration of a typical Spring web application look like?
|
||||
</h2>
|
||||
<p>
|
||||
The configuration of every Spring web application starts in web.xml.
|
||||
There, a Spring MVC DispatcherServlet is defined to process all requests into the application.
|
||||
The DispatcherServlet itself is configured using a Spring container.
|
||||
It is responsible for routing web requests to the proper application controllers, such as your Spring MVC @Controllers and web flows.
|
||||
A typical DispatcherServlet declaration is shown below:
|
||||
</p>
|
||||
<pre class="code">
|
||||
<!-- The front controller of this Spring MVC application, responsible for handling all application requests -->
|
||||
<servlet>
|
||||
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
|
||||
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
|
||||
<init-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>
|
||||
/WEB-INF/spring/*.xml
|
||||
</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
|
||||
<!-- Map all /app requests to the DispatcherServlet for handling -->
|
||||
<servlet-mapping>
|
||||
<servlet-name>Spring MVC Dispatcher Servlet</servlet-name>
|
||||
<url-pattern>/app/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
</pre>
|
||||
<p>
|
||||
This DispatcherServlet is configured to process requests into /app/*.
|
||||
The servlet's configuration is defined in the .xml files in /WEB-INF/spring.
|
||||
</p>
|
||||
<h2>
|
||||
How are Spring configuration files typically organized?
|
||||
</h2>
|
||||
<p>
|
||||
Inside /WEB-INF/spring, we generally recommend defining a configuration file for your application logic,
|
||||
and separate configuration files for framework infrastructure. For example:
|
||||
</p>
|
||||
<pre>
|
||||
/webapp
|
||||
/WEB-INF
|
||||
/spring
|
||||
app-config.xml
|
||||
mvc-config.xml
|
||||
webflow-config.xml
|
||||
</pre>
|
||||
<p>
|
||||
The example above shows the configuration for a Spring web application spread across three files.
|
||||
app-config.xml configures your components that carry out application-specific controller, business, and data access logic.
|
||||
mvc-config.xml configures the Spring MVC framework infrastructure, including the properties of the DispatcherServlet.
|
||||
webflow-config configures the Spring Web Flow infrastructure, which plugs into Spring MVC.
|
||||
</p>
|
||||
<h2>
|
||||
How do I plug-in Spring Web Flow?
|
||||
</h2>
|
||||
<p>
|
||||
In webflow-config.xml, first define a flow-registry to register the flows you have defined in your application:
|
||||
</p>
|
||||
<h2>
|
||||
How do I create and deploy new flows?
|
||||
</h2>
|
||||
<pre>
|
||||
<!-- Registers the web flows that can be executed -->
|
||||
<webflow:flow-registry id="flowRegistry" base-path="/WEB-INF/">
|
||||
<webflow:flow-location-pattern value="**/*-flow.xml" />
|
||||
</webflow:flow-registry>
|
||||
</pre>
|
||||
<p>
|
||||
The example above scans /WEB-INF looking for -flow.xml files and registers them.
|
||||
</p>
|
||||
<p>
|
||||
Then, define a flow-executor that uses this registry to execute your flows:
|
||||
</p>
|
||||
<pre>
|
||||
<!-- Configures the engine that executes web flows in this application -->
|
||||
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry" />
|
||||
</pre>
|
||||
<p>
|
||||
Finally, in mvc-config.xml plug in adapters to hook the flow-executor into the Spring MVC DispatcherServlet request processing pipeline:
|
||||
</p>
|
||||
<pre>
|
||||
<!-- Maps requests to flows in the flowRegistry -->
|
||||
<bean id="flowMappings" class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
|
||||
<property name="order" value="0" />
|
||||
<property name="flowRegistry" ref="flowRegistry" />
|
||||
</bean>
|
||||
|
||||
<!-- Enables Spring Web Flow as a Spring MVC request handler -->
|
||||
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
|
||||
<property name="flowExecutor" ref="flowExecutor" />
|
||||
</bean>
|
||||
</pre>
|
||||
<p>
|
||||
We also recommend you turn on development mode while developing so you never have to redeploy your application to test changes:
|
||||
</p>
|
||||
<pre>
|
||||
<webflow:flow-builder-services id="flowBuilderServices" development="true" />
|
||||
</pre>
|
||||
<p>
|
||||
<a href="tutorial?execution=${flowExecutionKey}&_eventId=next">Next ></a>
|
||||
</p>
|
||||
|
||||
Reference in New Issue
Block a user