Spring webflow 2 - url mapping not working

Web Dev picture Web Dev · May 17, 2012 · Viewed 9.7k times · Source

I'm using spring mvc 3 along with webflow 2. I have been following online resources and have been trying to get an example working. I am unable to get the webflow url mappings to work. It is only the webflow that is not working, the mvc part is working fine.

The error I keep getting is: No mapping found for HTTP request with URI [/Project2Admin/pizza] in DispatcherServlet with name 'appServlet'

I have pasted my servlet-context.xml below.

Your help is much appreciated! Odie


servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="http://www.springframework.org/schema/mvc     http://www.springframework.org/schema/mvc/spring-mvc-3.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
    http://www.springframework.org/schema/webflow-config http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven/>  

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<beans:bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver"/>

<beans:bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <beans:property name="definitions">
        <beans:list>
            <beans:value>/WEB-INF/views/**/views.xml</beans:value>
        </beans:list>
    </beans:property>
</beans:bean>

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
<beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
    <beans:property name="prefix" value="/WEB-INF/views/"/>
    <beans:property name="suffix" value=".jsp"/>
</beans:bean>

<context:component-scan base-package="com.project2.admin" />




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


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


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

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

<beans:bean class="com.example.PizzaFlowActions" id="pizzaFlowActions"/>


</beans:beans>

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

<!-- The definition of the Root Spring Container shared by all Servlets and Filters -->
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/spring/root-context.xml</param-value>
</context-param>

<!-- Creates the Spring Container shared by all Servlets and Filters -->
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<!-- Processes application requests -->
<servlet>
    <servlet-name>appServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring/appServlet/servlet-context.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>

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

</web-app>

version of servlet_context.html with only one view resolver (jstl view reolver). Both the mvc and webflow parts did not work with this setup.

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:flow="http://www.springframework.org/schema/webflow-config"
xsi:schemaLocation="http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.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
http://www.springframework.org/schema/webflow-config 
http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">

<!-- DispatcherServlet Context: defines this servlet's request-processing infrastructure -->

<!-- Enables the Spring MVC @Controller programming model -->
<annotation-driven/>  

<!-- Handles HTTP GET requests for /resources/** by efficiently serving up static resources in the ${webappRoot}/resources directory -->
<resources mapping="/resources/**" location="/resources/" />

<beans:bean class="org.springframework.web.servlet.view.tiles2.TilesViewResolver">
    <beans:property name="viewClass" value="org.springframework.web.servlet.view.tiles2.TilesView"/>
    <beans:property name="prefix" value="/WEB-INF/views/"/>
    <beans:property name="suffix" value=".jsp"/>
</beans:bean>

<beans:bean class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
    <beans:property name="definitions">
        <beans:list>
            <beans:value>/WEB-INF/views/**/views.xml</beans:value>
        </beans:list>
    </beans:property>
</beans:bean>


<context:component-scan base-package="com.project2.admin" />




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


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


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

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

<beans:bean class="com.example.PizzaFlowActions" id="pizzaFlowActions"/>


</beans:beans>

Answer

Patrick picture Patrick · May 21, 2012

Try changing your FlowHandlerMapping to

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

You are using the annotation driven configuration for Spring MVC which registers a default HandlerMapping for you, and I suspect it doesn't fall through to the next HandlerMapping. This has previously been reported as an issue. You want the WebFlow FlowHandlerMapping to come first - so you set the order to -1. This is what we have in our configs.