0

我正在尝试在我的 Spring Web Flow 应用程序中使用 FreeMarker。我在目录 flow/welcome/helloflow.xml 和 start.ftl 中配置了我的流程,代表 start-state

sevlet-context.xml 上的 FreeMarker 配置:

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
  <property name="templateLoaderPath" value="/WEB-INF/flows/welcome/"/>
</bean>
<bean id="viewResolver" class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver">
  <property name="cache" value="false"/>
  <property name="prefix" value=""/>
  <property name="suffix" value=".ftl"/>
</bean>

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

<webflow:flow-executor id="flowExecutor" />

<webflow:flow-registry id="flowRegistry">
  <webflow:flow-location path="/WEB-INF/flows/welcome/helloflow.xml"/>          
</webflow:flow-registry>

web.xml 重要部分:

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>  

  <servlet>
    <servlet-name>springapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>springapp</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>        

  <welcome-file-list>
    <welcome-file>
      index.ftl
    </welcome-file>
  </welcome-file-list>

helloflow.xml:

<view-state id="start">
    <transition on="next" to="end" />
</view-state>
<end-state id="end" />

我也没有什么特别的关于它的文件 start.ftl reperesenting start state。

然后当我尝试访问

http://localhost:8080/flows/welcome/helloflow

它告诉我“找不到访问 /WEB-INF/flows/welcome/start.jsp 的问题”所以即使我配置了 Freemarker 视图解析器,它也会搜索 start.jsp 而不是 start.ftl。

4

1 回答 1

0

在您的 web.xml 中,您不会将 Beans 配置文件映射到 Dispatcher Servlet。

您应该指定contextConfigLocationinit-param

<servlet>
    <servlet-name>springapp</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:<Location to>/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

或者作为一个context-param

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:<Location to>/servlet-context.xml</param-value>
</context-param>

这可以很好地解决您的问题。

于 2013-06-13T09:25:29.927 回答