Spring寻找.jsp而不是.ftl

时间:2013-06-11 09:22:27

标签: spring-webflow freemarker

我正在尝试在Spring Web Flow应用程序中使用FreeMarker。 我在目录流/ welcome / helloflow.xml和start.ftl中配置了我的流程,表示开始状态

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反复启动状态。

然后当我尝试访问

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

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

1 个答案:

答案 0 :(得分:0)

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

您应该将contextConfigLocation指定为init-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>

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