【问题标题】:No mapping found for HTTP request with URI - JSF resource using Spring WebFlow找不到带有 URI 的 HTTP 请求的映射 - 使用 Spring WebFlow 的 JSF 资源
【发布时间】:2012-03-17 14:36:31
【问题描述】:

我正在尝试使用 JSF (Primefaces 3.1.1) 和 Spring WebFow 2.3 设置一个 Web 项目。我能够部署和启动我的索引页面,但我注意到 p:commandButton 似乎没有 Primeface 的外观和感觉。

当我启动应用程序时,我在 IDE 控制台上看到以下警告:

WARNING: No mapping found for HTTP request with URI [/client-ui/contact/javax.faces.resource/primefaces.css] in DispatcherServlet with name 'DispatcherMVC'
WARNING: No mapping found for HTTP request with URI [/client-ui/contact/javax.faces.resource/theme.css] in DispatcherServlet with name 'DispatcherMVC'
WARNING: No mapping found for HTTP request with URI [/client-ui/contact/javax.faces.resource/primefaces.js] in DispatcherServlet with name 'DispatcherMVC'
WARNING: No mapping found for HTTP request with URI [/client-ui/contact/javax.faces.resource/jquery/jquery.js] in DispatcherServlet with name 'DispatcherMVC'

WEB-INF/web.xml

<?xml version="1.0"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                         "http://java.sun.com/dtd/web-app_3_0.xsd">
<web-app>
    <display-name>Buttery Bees web client ui</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/config/*-context.xml</param-value>
    </context-param>   
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet> 
        <servlet-name>Faces Servlet</servlet-name>
        <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>DispatcherMVC</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/config/webmvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet>
        <servlet-name>Resources Servlet</servlet-name>
        <servlet-class>org.springframework.js.resource.ResourceServlet</servlet-class>
        <load-on-startup>0</load-on-startup>
    </servlet>  

    <servlet-mapping>
        <servlet-name>Faces Servlet</servlet-name>
        <url-pattern>*.jsf</url-pattern>
    </servlet-mapping>  
    <servlet-mapping>
        <servlet-name>DispatcherMVC</servlet-name>
        <url-pattern>/contact/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Resources Servlet</servlet-name>
        <url-pattern>/resources/*</url-pattern>
    </servlet-mapping>    

    <welcome-file-list>
        <welcome-file>/index.jsp</welcome-file>
    </welcome-file-list>
</web-app>

WEB-INF/config/webmvc-config.xml

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

    <mvc:annotation-driven/>

    <context:component-scan base-package="com.bb.ui.controller" />

    <mvc:resources location="/WEB-INF/web-content/" mapping="/WEB-INF/web-content/**"/>

    <bean id="facesViewResolver" class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass" value="org.springframework.faces.mvc.JsfView" />
        <property name="prefix" value="/WEB-INF/web-content/pages/" />
        <property name="suffix" value=".xhtml" />
    </bean> 

    <import resource="webflow-config.xml" />    
</beans>

WEB-INF/config/webflow-config.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:webflow="http://www.springframework.org/schema/webflow-config"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
                        http://www.springframework.org/schema/webflow-config 
                        http://www.springframework.org/schema/webflow-config/spring-webflow-config-2.0.xsd">

    <!--Maps request paths to flows in the flowRegistry--> 
    <bean class="org.springframework.webflow.mvc.servlet.FlowHandlerMapping"> 
        <property name="order" value="0" /> 
        <property name="flowRegistry" ref="flowRegistry" /> 
    </bean>

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

    <!-- Executes flows: the entry point into the Spring Web Flow system -->
    <webflow:flow-executor id="flowExecutor" />

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

    <!-- Plugs in a custom creator for Web Flow views -->
    <webflow:flow-builder-services id="flowBuilderServices" view-factory-creator="mvcViewFactoryCreator" development="true" />

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

WEB-INF/web-content/pages/index.xhtml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
       xmlns:ui="http://java.sun.com/jsf/facelets"
       xmlns:h="http://java.sun.com/jsf/html"
       xmlns:f="http://java.sun.com/jsf/core"
       xmlns:p="http://primefaces.org/ui">
<h:head>


</h:head>
<h:body>
    <h:form>
        <p:panel>
            <p:commandButton value="Primeface Button"/>
            something
        </p:panel>
    </h:form>
</h:body>

</html>

HomeController.java

package com.bb.ui.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping ("/contact")
public class HomeController {
    @RequestMapping ("/contact")
    public String home() {
        return "index";
    }
}

webapp/index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=contact">
</head>
</html>

【问题讨论】:

  • 我在 GlassFish 3.1 上部署
  • 您的 Spring 调度程序 servlet 映射到 /* 的 URL 模式。所以它会拦截每个 URL,还有CSS/JS/images/etc。事实证明,调度器 servlet 不知道如何处理它们,所以它们只是被吞没了,所以 webbrowser 不会得到任何 CSS/JS/图像,所以外观完全被破坏了。顺便说一句,修复你的 web.xml 根声明以匹配 Servlet 3.0 XSD,你有一个古老的 Servlet 2.3 DTD 声明,它会导致一切以 Servlet 2.3 兼容性方式运行。
  • @BalusC - 我尝试将 URL 模式从 /* 更改为 *.do。然后,我将 HomeController.java 中的 @RequestMapping 从“/”更改为“home.do”,但是当我尝试启动应用程序时得到以下信息 --- WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception java.lang.NullPointerException at org.springframework.faces.webflow.FlowViewStateManager.saveView(FlowViewStateManager.java:181) --- 我确定我错过了一些基础知识,所以我会继续阅读。您可以提供的任何提示都会很棒。感谢您的耐心等待。
  • 另外,我尝试了 / 而不是 /* 的 URL 模式。该应用程序启动时带有非常相似的警告WARNING: No mapping found for HTTP request with URI [/client-ui//javax.faces.resource/jquery/jquery.js] in DispatcherServlet with name 'DispatcherMVC'
  • 对不起,我不做Spring,所以我不能对那部分给出详细的答案。顺便说一句,您的 web.xml 根声明仍然被破坏。从 Servlet 2.4 开始,它是 XSD,而不是 DTD。

标签: jsf primefaces spring-webflow


【解决方案1】:

BalusC 的 cmets 是正确的,但是即使您遵循他的建议,您仍然可能会遇到 Primefaces 组件无法正确渲染的问题。您尚未在 web.xml 中映射 Primefaces 资源 Servlet。

<servlet>
  <servlet-name>Resource Servlet</servlet-name>
  <servlet-class>org.primefaces.resource.ResourceServlet</servlet-class>
</servlet>
<servlet-mapping>
  <servlet-name>Resource Servlet</servlet-name>
  <url-pattern>/primefaces_resource/*</url-pattern>
</servlet-mapping>

此 servlet 名称与您的 WebFlow 资源 servlet 的 Servlet 名称冲突,因此您还需要解决此名称差异。

【讨论】:

【解决方案2】:

正如spring show case sample中所述:

启用对 JSF 2 资源请求的处理。例如:

/webflow-primefaces-showcase/app/javax.faces.resource/jsf.js?ln=javax.faces

尝试将此添加到您的 MVC 配置中:

    <faces:resources/>

在某些情况下,声明了多个资源,也有必要使用显式 order 属性。例如:

    <mvc:resources mapping="/resources/**" location="/"/>
    <faces:resources order="-1"/>

【讨论】:

    【解决方案3】:

    我为我的应用解决了这个问题

    WEB-INF/config/webmvc-config.xml 中将 order 0 设置为 mvc:resources

    <mvc:resources order="0" location="/WEB-INF/web-content/" mapping="/WEB-INF/web-content/**"/>
    

    然后在 WEB-INF/config/webflow-config.xml 中将 FlowHandlerMappin 的 order 值更改为更大的值:

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

    这就足够了,但我建议你也从 web.xml 中删除 ResourceServlet,mvc:resources 不再需要它了

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-09-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-05
      • 2011-12-08
      相关资源
      最近更新 更多