2012-03-27 25 views
1

我收到以下错误在我的日志:春3.1.1的SAXParseException与MVC:资源

产生的原因:org.xml.sax.SAXParseException:CVC-复杂type.2.4.c:本匹配通配符是严格的,但是对元素'mvc:resources'没有声明。

这说明,当我尝试在浏览器中查看我的应用程序:

错误500:javax.servlet.ServletException:SRVE0207E:由servlet的创建

这里未捕获的初始化异常是我的web.xml:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app 
    id="WebApp_ID" 
    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"> 
    <display-name>MyAwesomeApp</display-name> 
    <welcome-file-list> 
     <welcome-file>index.html</welcome-file> 
     <welcome-file>index.htm</welcome-file> 
     <welcome-file>index.jsp</welcome-file> 
     <welcome-file>default.html</welcome-file> 
     <welcome-file>default.htm</welcome-file> 
     <welcome-file>default.jsp</welcome-file> 
    </welcome-file-list> 
    <servlet> 
     <servlet-name>spring</servlet-name> 
     <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> 
     <load-on-startup>1</load-on-startup> 
    </servlet> 
    <servlet-mapping> 
     <servlet-name>spring</servlet-name> 
     <url-pattern>/</url-pattern> 
    </servlet-mapping> 
</web-app> 

这是我的spring-servlet.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:mvc="http://www.springframework.org/schema/mvc" 
    xmlns:context="http://www.springframework.org/schema/context" 
    xsi:schemaLocation=" 
      http://www.springframework.org/schema/beans 
      http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
      http://www.springframework.org/schema/mvc/spring-mvc 
      http://www.springframework.org/schema/mvc/spring-mvc-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="org.myapp.controllers" /> 
    <bean 
     id="viewResolver" 
     class="org.springframework.web.servlet.view.UrlBasedViewResolver"> 
     <property 
      name="viewClass" 
      value="org.springframework.web.servlet.view.JstlView" /> 
     <property 
      name="prefix" 
      value="/WEB-INF/views/" /> 
     <property 
      name="suffix" 
      value=".jsp" /> 
    </bean> 
    <mvc:resources 
     mapping="/resources/**" 
     location="/resources/" /> 
</beans> 

我在做什么错?如果我拿出<mvc:resources标签,我的应用出现,但它的CSS不加载。

编辑:也许我有一些其他问题,因为现在我没有得到那个错误,虽然我的应用程序不显示 - 我只是得到了404。现在,它看起来很有希望:

SimpleUrlHand我org.springframework.web.servlet.handler.AbstractUrlHandlerMapping registerHandler映射的URL路径[/资源/ **]在处理“org.springframework.web.servlet.resource.ResourceHttpRequestHandler #0'

+0

您发布的第一个异常表明存在解析xml文件'spring-servlet.xml'的问题 – 2012-03-27 20:23:47

回答

2

您在命名空间声明中犯了错误spring-servlet.xml。 请更改:

xsi:schemaLocation=" 
(...) 
http://www.springframework.org/schema/mvc/spring-mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
(...)" 

到:

xsi:schemaLocation=" 
(...) 
http://www.springframework.org/schema/mvc/mvc 
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
(...)" 

既然你宣布

xmlns:mvc="http://www.springframework.org/schema/mvc" 

(...)/schema/spring-mvc

0

我结束了以下this tutorial,使用Spring MVC Project模板创建一个新的Spring模板项目。然后我创建了一个EAR(Rational Application Developer中的新的企业应用程序项目),其中包括我的新的Spring MVC项目。将EAR部署到我的WAS 7,一切都很好。我把我的CSS和JavaScript文件放在src/main/webapp/resources中,并在resources/stylesheet.css的视图中链接到它们。模板项目带有一个已经设置的资源目录。

我也注意到,它的上下文文件中的xmlns和xsi:schemaLocation都引用http://www.springframework.org/schema/mvc,不http://www.springframework.org/schema/mvc/spring-mvc我在xsi:schemaLocation一样,所以我觉得Piotrek's answer可能是正确的。