首页 > 解决方案 > 不支持的视图类型 /WEB-INF/index.xhtml 仅此 FlowViewResolver 实现支持的类型是 [.jsp] 和 [.jspx]

问题描述

我们在 Spring-webflow 配置和视图重定向方面存在问题。

登录后,您应该进入配置的主页,但您会被重定向到错误页面。

查看log trace,验证在登录提交时,会重定向到对应的view,但是控制view的spring组件出错,只允许jsp和jspx。

我们正在使用 Spring-webflow 2.4.1、Spring-mvc 3.1.4、jsf 2.2 和 primefaces 4.0。

我们一直在验证如何使用 xml 执行此操作的不同方法,因为它是一个旧应用程序,我们正在做的是从 ant 重构为 maven,以便继续进行所需的修改。

生成的错误如下:

11:15:32,603 信息 [stdout] (http-localhost/127.0.0.1:8080-5) 10-06-2020 11:15:32,602 [调试] [http-localhost/127.0.0.1:8080-5] [org .springframework.webflow.engine.impl.FlowExecutionImpl] 试图处理 [org.springframework.webflow.execution.FlowExecutionException: 异常在流 'start-flow' 的状态 'index' 中抛出] 根本原因 [java.lang.IllegalArgumentException:不受支持的视图类型 /WEB-INF/index.xhtml 仅此 FlowViewResolver 实现支持的类型是 [.jsp] 和 [.jspx]] 11:15:32,603 错误 [com.axa.ca.caem.web.core.exception. CaemExceptionHandler] (http-localhost/127.0.0.1:8080-5) 处理异常 11:15:32,603 INFO [stdout] (http-localhost/127.0.0.1:8080-5) 10-06-2020 11:15:32,603 [错误] [http-localhost/127.0.0.1:8080-5] [com.axa.ca.caem.web.core.exception。CaemExceptionHandler] 处理异常 11:15:32,604 错误 [com.axa.ca.caem.web.core.exception.CaemExceptionHandler] (http-localhost/127.0.0.1:8080-5) 在 CaemExceptionHandler 中捕获的未知错误:java.lang.IllegalArgumentException:不支持的视图类型/WEB-INF/index.xhtml 只有 在 org.springframework.webflow.mvc.builder.FlowResourceFlowViewResolver.getViewInternal(FlowResourceFlowViewResolver .java:94) [spring-webflow-2.4.1.RELEASE.jar:2.4.1.RELEASE]

配置文件为: spring-webflow.xml

<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"
    xmlns:faces="http://www.springframework.org/schema/faces"
    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
        http://www.springframework.org/schema/faces http://www.springframework.org/schema/faces/spring-faces.xsd">

    <faces:resources/>

    <!-- Maps request paths to flows in the flowRegistry; localeChangeInterceptor 
    is used for intercepting internationalization changes -->
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping">
        <property name="flowRegistry" ref="flowRegistry" />
        <property name="interceptors">
            <list>
                <ref bean="localeChangeInterceptor"></ref>
            </list>
        </property>
        <property name="order" value="0"/>
    </bean>

    <bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">
        <property name="flowExecutor" ref="flowExecutor" />
    </bean>

    <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
        <webflow:flow-execution-listeners>
            <webflow:listener ref="facesContextListener"/>
            <webflow:listener ref="securityListener"/>
        </webflow:flow-execution-listeners>
    </webflow:flow-executor> 

    <!-- Registramos todos nuestros flujos con la dupla id-xml -->
    <webflow:flow-registry id="flowRegistry" base-path="/WEB-INF/flows">  
        <webflow:flow-location-pattern value="/**.xml" />
        <webflow:flow-location id="parent-flow" path="parent-flow.xml" />
    </webflow:flow-registry>  

    <webflow:flow-builder-services id="flowBuilderServices" />  

    <!-- Mapea a nombres logicos de vista to recursos fisicos -->
    <!-- Maps logical view names to Facelet templates in /WEB-INF (e.g. 'search' to '/WEB-INF/search.xhtml' -->
    <bean class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.faces.mvc.JsfView"/>
        <property name="prefix" value="/WEB-INF/views/" />
        <property name="suffix" value=".xhtml" />
    </bean>

    <!-- A listener to create and release a FacesContext -->
    <bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>

</beans>

提前致谢。

标签: springjsfspring-webflow

解决方案


这对我来说是正确的配置。谢谢!

<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"
   xmlns:faces="http://www.springframework.org/schema/faces"
   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
        http://www.springframework.org/schema/faces 
        http://www.springframework.org/schema/faces/spring-faces.xsd">

    <faces:resources/>

    <!-- Spring Webflow central configuration component -->
    <webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
        <webflow:flow-execution-listeners>          
            <webflow:listener ref="facesContextListener"/>          
            <webflow:listener ref="securityListener"/>
        </webflow:flow-execution-listeners>
    </webflow:flow-executor>

    <!-- Installs a listener that creates and releases the FacesContext for each request. -->   
    <bean id="facesContextListener" class="org.springframework.faces.webflow.FlowFacesContextLifecycleListener"/>   

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

    <!-- Configures the Spring Web Flow JSF integration --> 
    <faces:flow-builder-services id="facesFlowBuilderServices" development="true" />

    <bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator">
        <property name="viewResolvers">
            <list>
                <ref bean="viewResolver"/>
            </list>
        </property>     
    </bean>

    <bean id="viewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver">
          <property name="prefix" value="/WEB-INF/views/"/>
          <property name="suffix" value=".xhtml" />
    </bean>

    <!-- Dispatches requests mapped to flows to FlowHandler implementations --> 
    <bean class="org.springframework.faces.webflow.JsfFlowHandlerAdapter">      
        <property name="flowExecutor" ref="flowExecutor" /> 
    </bean>

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

</beans>

推荐阅读