Spring Web Flow. Hello World! Частина 4. Налаштування програми

січня
05
2012
Мітки: spring spring web flow

Зміст

У цій статті буде показано як налаштувати проект для подальшого використання Spring Web Flow.

Конфігураційний файл сервлета SWFHelloWorld (/WEB-INF/SWFHelloWorld-servlet.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.0.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.seostella.swfhelloworld" />

    <flow:flow-executor id="flowExecutor" flow-registry="flowRegistry" />

    <flow:flow-registry id="flowRegistry" 
                        flow-builder-services="flowBuilderServices"
                        base-path="/WEB-INF/flows">
        <flow:flow-location-pattern value="/**/*-flow.xml" />
    </flow:flow-registry>

    <flow:flow-builder-services id="flowBuilderServices" 
                                view-factory-creator="mvcViewFactoryCreator"/>

    <bean id="mvcViewFactoryCreator" 
              class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
        <property name="defaultViewSuffix" value=".jspx" />   
    </bean>

    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="flowRegistry" ref="flowRegistry" />
    </bean>

    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor" />
    </bean>
</beans>

Ця стаття не ставить своїм завданням повністю розкрити тему використання Spring Web Flow. Тому розглянемо тільки 2 фрагменти з цієї конфігурації. Перший фрагмент:


    ...
    <context:component-scan base-package="com.seostella.swfhelloworld" />
    ...

com.seostella.swfhelloworld - пакет, в якому відбуватиметься пошук на компоненти програми та, власне, обробник дій. У даному прикладі в пакеті com.seostella.swfhelloworld не буде класів, але в майбутньому ця конструкція нам ще знадобиться.

Наступним кодом визначаємо, що наші списки дій будуть лежати в піддиректорії директорії /WEB-INF/flows та ім'я файлу буде закінчуватися на -flow.xml. Наприклад, /WEB-INF/flows/signin/signin-flow.xml.


    ...
    <flow:flow-registry id="flowRegistry" 
                        flow-builder-services="flowBuilderServices"
                        base-path="/WEB-INF/flows">
        <flow:flow-location-pattern value="/**/*-flow.xml" />
    </flow:flow-registry>
    ...

У завершальній частині статті представлено фінальну веб-програму...

< Spring Web Flow. Hello World! Частина 3. Налаштування SWF Spring Web Flow. Hello World! Частина 5 >

Напишіть перше повідомлення!

Ви повинні увійти під своїм аккаунтом щоб залишати коментарі