2012-05-17 43 views
1

我使用spring mvc 3以及webflow 2.我一直在關注在線資源,並一直試圖獲得一個示例工作。我無法讓webflow url映射工作。只有webflow不工作,mvc部分工作正常。春天webflow 2 - url映射不起作用

我不斷收到的錯誤是: 沒有映射的DispatcherServlet發現HTTP請求的URI與[/ Project2Admin /比薩餅]名爲 'appServlet'

我已經粘貼下面我的servlet-context.xml中。

非常感謝您的幫助! 歐迪


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> 

版本servlet_context.html的僅具有一個視圖解析器(JSTL查看reolver)。 mvc和webflow部件都無法使用此設置。

<?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> 
+0

你能顯示你的web.xml文件嗎? –

+0

Hi日本Trivedi,謝謝你的迴應。我現在也粘貼了我的web.xml。 –

回答

0

我認爲這裏的問題是在你的servlet-context.xml文件中有兩個不同的視圖解析器。

請刪除的InternalResourceViewResolver,並把在的viewClass類,前綴和後綴屬性TilesViewResolver豆。

根據我這應該解決您的問題。

乾杯。

+0

嗨Trivedi,謝謝你的迴應。我遵循你的建議..見上面我的新servlet-context.xml。這並沒有解決問題。網絡流量不起作用。它以前工作的mvc部分現在不工作..我認爲這是因爲我有@controller註釋類給出的視圖需要InternalResourceViewResolver。無論如何感謝您的幫助。歐弟。 –

1

我設法通過爲webflow創建一個調度器servlet來解決問題。我不確定這是否是理想的解決方案,但它的工作原理。 mvc和webflow都可以正常工作。

如果有人知道更優雅的方式來處理這個問題..即只使用一個調度程序servlet來處理mvc和webflow調用,請發佈一個答案,您的幫助將不勝感激。

謝謝!


的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> 
    <servlet-name>flowServlet</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value>/WEB-INF/spring/flow-context.xml</param-value> 
    </init-param> 
    <load-on-startup>2</load-on-startup> 
</servlet> 


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

<servlet-mapping> 
    <servlet-name>flowServlet</servlet-name> 
    <url-pattern>/flow/*</url-pattern> 
</servlet-mapping> 

</web-app> 

流的context.xml:

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

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

<!-- Executes flows: the entry point into the Spring Web Flow system --> 

<!--<start id="flow_executor"/>--> 
<flow:flow-executor id="flowExecutor" flow-registry="flowRegistry" /> 
<!--<end id="flow_executor"/>--> 

<!-- The registry of executable flow definitions --> 
<!--<start id="flow_registry"/>--> 
<flow:flow-registry id="flowRegistry" flow-builder-services="flowBuilderServices" base-path="/WEB-INF/flows"> 
<flow:flow-location-pattern value="/**/*-flow.xml" /> 
</flow:flow-registry> 

<flow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator"/> 
<!--<end id="flow_registry"/>--> 

<!--<start id="mvcFactoryCreator"/>--> 
<bean id="mvcViewFactoryCreator" class="org.springframework.webflow.mvc.builder.MvcViewFactoryCreator"> 
<property name="defaultViewSuffix" value=".jspx" /> 
</bean> 
<!--<end id="mvcFactoryCreator"/>--> 

<!--Maps request paths to flows in the flowRegistry--> 
<!--<start id="flowHandlerMapping"/>--> 
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> 
<property name="flowRegistry" ref="flowRegistry" /> 
</bean> 
<!--<end id="flowHandlerMapping"/>--> 

<!-- 
Dispatches requests mapped to flows to FlowHandler implementations 
--> 
<!--<start id="flowHandlerAdapter"/>--> 
<bean class="org.springframework.webflow.mvc.servlet.FlowHandlerAdapter"> 
<property name="flowExecutor" ref="flowExecutor" /> 
</bean> 
<!--<end id="flowHandlerAdapter"/>--> 

</beans> 
4

試着改變你的FlowHandlerMapping

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

您正在使用Spring MVC的註釋驅動配置,它爲您註冊一個默認的HandlerMapping,我懷疑它不會落入下一個HandlerMapping。這已被報告爲issue。您希望WebFlow FlowHandlerMapping排在第一位 - 因此您將順序設置爲-1。這就是我們的配置。

0

一切工作正常,我既一個Webflow和Spring MVC

這裏是我的我的web.xml文件的一部分:

<servlet> 
    <servlet-name>web-dispatcher</servlet-name> 
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
    <init-param> 
     <param-name>contextConfigLocation</param-name> 
     <param-value></param-value> 
    </init-param> 
    <load-on-startup>1</load-on-startup> 
</servlet> 
<servlet-mapping> 
    <servlet-name>web-dispatcher</servlet-name> 
    <url-pattern>*.do</url-pattern> 
</servlet-mapping> 
<servlet-mapping> 
    <servlet-name>web-dispatcher</servlet-name> 
    <url-pattern>/public/*</url-pattern> 
</servlet-mapping> 
<servlet-mapping> 
    <servlet-name>web-dispatcher</servlet-name> 
    <url-pattern>/error/*</url-pattern> 
</servlet-mapping> 

和我的網絡調度員:

<bean id="viewNameTranslator" class="org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator" /> 

<bean id="basicViewResolver" class="org.springframework.web.servlet.view.ResourceBundleViewResolver" > 
    <property name="basename" value="views"/> 
</bean> 

<!-- Resolves logical view names returned by Controllers to Tiles; a view name to resolve is treated as the name of a tiles definition --> 
<bean id="tilesViewResolver" class="org.springframework.js.ajax.AjaxUrlBasedViewResolver"> 
    <property name="viewClass" value="org.springframework.webflow.mvc.view.FlowAjaxTilesView"/> 
</bean> 

<!-- Configures the Tiles layout system --> 
<bean id="tilesConfigurer" class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"> 
    <property name="definitions"> 
     <list> 
      <value>/WEB-INF/jsp/views.xml</value> 
      <value>/WEB-INF/jsp/fragments/views.xml</value> 
      <!-- Flow views --> 
      <value>/WEB-INF/flows/**/views.xml</value>    
      <!-- PUBLIC Pages --> 
      <value>/WEB-INF/jsp/public/views.xml</value> 
     </list> 
    </property> 
</bean> 

希望這可以幫助