Spring Webflow 2.4.2 缺少启动状态

Spring Webflow 2.4.2 missing start state

我刚开始将 Webflow 添加到 Spring MVC 项目,我在 flow.xml 组件上遇到此编译错误:

Start state is missing. Add at least one state to the flow

我在一年前的 SO 上发现了一个完全相同的 post:webflow.xsd - Start state is missing. Add at least one state to the flow。 没有人回答这个问题,但我在 Spring Webflow 的 Jira 存储库中找到了它:webflow.xsd - Start state is missing. Add at least one state to the flow。它被标记为无法复制。

这是我非常简单的网站的摘录flow.xml。

    <?xml version="1.0" encoding="UTF-8"?>
    <flow xmlns="http://www.springframework.org/schema/webflow"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://www.springframework.org/schema/webflow
            http://www.springframework.org/schema/webflow/spring-webflow-2.4.xsd">

    <on-start>
        <evaluate expression="recipeService.createRecipe(currentUser.name)" result="flowScope.recipe" />
    </on-start>

    <view-state id="basics" view="recipe/basics" model="recipe">
        <transition on="proceed" to="ingredients"></transition>
        <transition on="cancel" to="cancel"></transition>
    </view-state>

    ... more states ...

    <end-state id="end" view="recipe/end"/>
    <end-state id="cancel" view="recipe/end"/>

    </flow>

文档表明开始状态是可选的 - 第一个视图状态将被假定为开始。如果我将 spring-webflow-2.4.xsd 更改为 2.0,错误就会消失,但如果我尝试在任何视图状态条目上使用验证提示,则会出现不同的错误。下面示例中的 "Basic1" 和 "Basic2" 是配方模型上的验证组。

<view-state id="basics" view="recipe/basics" model="recipe" validation-hints="'basic1,basic2'">

我正在使用

我对所有内容都使用基于 java 的配置,但我认为这不是问题所在,除非我的 Webflow 2.4.2 要求的版本不匹配?如果有帮助,我可以 post 我的 WebMvcConfig 和 WebFlowConfig 或 pom.xml 或任何其他信息。

如有任何帮助,我们将不胜感激。

编辑 #1:摘自 java 配置

    From WebFlowConfig.java: 
    @Bean
    public FlowDefinitionRegistry flowRegistry() {
        return getFlowDefinitionRegistryBuilder(flowBuilderServices())
            .setBasePath("/WEB-INF/views")
            .addFlowLocationPattern("/**/*-flow.xml")
            .build();               
    }

    From WebMvcConfig.java
    @Override
    public void addViewControllers(final ViewControllerRegistry registry) {
        super.addViewControllers(registry);
        registry.addViewController("/recipe/basics.htm");        
        registry.addViewController("/recipe/ingredients.htm");
        registry.addViewController("/recipe/instructions.htm");
        registry.addViewController("/recipe/optional.htm");
        registry.addViewController("/recipe/end.htm");
    }

使用 2.0 所有页面都以正确的顺序执行。

编辑 #2

我忘了说,即使出现 2.4 xsd 编译错误,webflow 也会执行,与一年前的 post 相同。我还发现了这个关于 STS 的问题:webflow config gives incorrect "Start state definition is missing." error。指示的修复版本是 3.3.0.M1,所以我假设 (?) 该修复仍包含在 STS 3.6.4 中。

这是 2.0 和 2.4 xsd 之间的区别

http://diffchecker.com/oqx5rq7t

唯一的区别是添加了 validation-hints 属性。

不确定还能从中推断出什么。也许这是 eclipse/STS 解析 xsd 文件的方式的错误。

正如 Rossen 在 SWF jira ticket 中指出的,xsd 中的每个子元素都用 minOccurs="0" https://jira.spring.io/browse/SWF-1646

定义

所以我认为这不是 SWF 问题,而是 STS/Eclipse 解析问题。

我花了几个小时尝试我能想到的一切,包括用 booking-mvc 示例项目中的 pom.xml 的内容替换 pom.xml 中的几乎所有内容,该项目没有显示这个尽管也被设置为 2.4.2 版,但仍出现错误。由于 webflow 似乎绑定到 Thymeleaf 和 Tiles(我没有使用),我认为这些项目中可能存在依赖关系,可以消除错误。没有。

所以我查看了 booking-mvc 项目的属性,并将它们与我的进行了比较。我能看到的唯一相关区别是 Spring |网络流量支持。我的项目列出了我的 recipe-flow.xml,但 booking-mvc 没有显示它的 -flow.xml 文件。一旦我删除了我的 flow.xml 文件,错误就消失了。

我不知道该文件是如何出现在这个配置位置的,我找不到任何关于这个 属性 的用途的文档,但显然这是一个禁忌,至少在我的项目中是这样.我的 pom.xml 花了一段时间才恢复原状,但该应用程序现在又能正常工作了。

我终于找到了解决方案。

Eclipse 认为 "Start state is missing" 因为他认为 XML 是 "Spring Web Flow Definition File",但他错了。 解决方案是告诉 Eclipse XML 不是 "Spring Web Flow Definition File".

打开"Spring Explorer",会发现"Web Flow"中显示的XML,右击select "Properties",可以看到[=27] =] 在 "Web Flow Support / Config Files" 列表中。删除它即可。