【问题标题】:The matching wildcard is strict, but no declaration can be found for element 'resources'匹配的通配符是严格的,但找不到元素“资源”的声明
【发布时间】:2012-11-18 16:59:07
【问题描述】:

我知道这是重复的,你们会为此责备我,但在阅读了所有帖子后我没有得到正确的解决方案。
我正在尝试在 Spring Source Tool Suite 中构建一个 Spring Template 应用程序。 我收到以下错误。

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:来自 ServletContext 资源 [/WEB-INF/spring/appServlet/servlet-context.xml] 的 XML 文档中的第 16 行无效;嵌套异常是 org.xml.sax.SAXParseException:cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素“资源”的声明。

我的 root-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:aop="http://www.springframework.org/schema/aop"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:cache="http://www.springframework.org/schema/cache"
    xmlns:ehcache="http://www.springmodules.org/schema/ehcache"
    xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
        http://www.springmodules.org/schema/ehcache http://www.springmodules.org/schema/cache/springmodules-ehcache.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.0.xsd">

    <!-- Root Context: defines shared resources visible to all other web components -->

</beans>

如果我的应用程序中缺少 jar 文件,请告诉我。
这些是我的应用程序中仅有的 jar 文件:
displaytag-1.0-b3.jar、spring-2.0.6.jar、spring-asm-3.0.3.RELEASE.jar、spring-beans-3.0.3.RELEASE.jar、spring-context-3.0.3.RELEASE。 jar、spring-core-3.0.3.RELEASE.jar、spring-expression-3.0.3.RELEASE.jar、spring-hibernate3-2.0.8.jar、spring-web-3.0.3.RELEASE.jar & spring- webmvc-3.0.3.RELEASE.jar

这是我的 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"
    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">

    <!-- 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/" />

    <!-- 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="prefix" value="/WEB-INF/views/" />
        <beans:property name="suffix" value=".jsp" />
    </beans:bean>

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



</beans:beans>

请帮忙...这真的很烦人。

【问题讨论】:

  • 你为什么不发布实际的 XML,包括“资源”元素?
  • @MarkoTopolnik 我真的不明白你在说哪个 xml 文件。这个 context.xml 就是我所拥有的。有了这个文件,就会出现我提到的错误。
  • 该错误与元素“resources”有关,它可能出现在您的 XML 中。
  • @MarkoTopolnik 感谢您的快速回复。我的 xml 中没有这样的元素,你发现了它。但是不知道xml文件中是否有这样的元素要添加。你能指导我吗?
  • 显示您的 /WEB-INF/spring/appServlet/servlet-context.xml 文件。

标签: java spring spring-mvc spring-security


【解决方案1】:

您的 XML 很好,但根据 this comment on a SpringSource blog post about Spring MVC 3

&lt;mvc:resources/&gt; 标签是 Spring Framework 3.0.4 中的一个新特性

您的应用程序使用 Spring 3.0.3,因此您需要升级到 3.0.4 或更高版本才能使用资源标签。

【讨论】:

  • 感谢您的回答。我尝试将标签更改为 但仍然出现错误。
  • Robert 现在我应该将我的 jar 文件升级到 spring 3.0.4 还是更改任何标签?请帮忙...
  • @Freakyuser 您的 XML 首先是正确的,您正在使用本地名称为 resources 和命名空间 URI http://www.springframework.org/schema/mvc 的 XML 元素(使用它作为 XML 文件的默认命名空间而不是使用“beans”命名空间作为默认命名空间并将 MVC 命名空间映射到前缀的更常用方法,但从 XML 的角度来看,这两种方法是等效的)。但是 3.0.3 根本不支持这个元素,你必须升级才能让它工作。
猜你喜欢
  • 2012-08-26
  • 2021-11-02
  • 2017-10-20
  • 2014-08-07
  • 1970-01-01
  • 1970-01-01
  • 2015-12-05
  • 2011-08-28
  • 2012-11-15
相关资源
最近更新 更多