<mvc:resources>类型未解析</mvc:resources>

时间:2010-09-22 13:48:39

标签: spring spring-mvc

我正在尝试构建这里提供的mvc-showcase示例link

但我收到以下错误:

  

cvc-complex-type.2.4.c:匹配的通配符是strict,但是没有为元素'resources'找到声明。

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

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

    <!-- Enables the Spring MVC @Controller programming model -->
    <annotation-driven conversion-service="conversionService" />

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

    <!-- Imports user-defined @Controller beans that process client requests -->
    <beans:import resource="controllers.xml" />

    <!-- Only needed because we install custom converters to support the examples in the org.springframewok.samples.mvc.convert package -->
    <beans:bean id="conversionService" class="org.springframework.samples.mvc.convert.CustomConversionServiceFactoryBean" />

    <!-- Only needed because we require fileupload in the org.springframework.samples.mvc.fileupload package -->
    <beans:bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />   
</beans:beans> 

注意:我正在使用Eclipse IDE,我正在使用spring 3.0.4版本(因为我使用的是项目link中提供的相同pom.xml)

4 个答案:

答案 0 :(得分:4)

标记是Spring Framework 3.0.4中的新功能,因此请检查您的spring版本。

干杯

答案 1 :(得分:1)

我在标签上遇到了同样的问题。问题是你的春季版本,因为@Drolyk sad在版本3.0.4或更高版本中可用,所以我会给你我的依赖项,我相信如果你使用它们你将解决这个问题:

    <!-- BEGINING OF FULL SPRING 3 DEPENDENCES -->
  <!-- Shared version number properties -->
<properties>
    <org.springframework.version>3.0.5.RELEASE</org.springframework.version>
</properties>
<!--Core utilities used by other modules.
    Define this if you use Spring Utility APIs (org.springframework.core.*/org.springframework.util.*)-->
 <dependencies>
 <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Expression Language (depends on spring-core)
    Define this if you use Spring Expression APIs (org.springframework.expression.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-expression</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Bean Factory and JavaBeans utilities (depends on spring-core)
    Define this if you use Spring Bean APIs (org.springframework.beans.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Aspect Oriented Programming (AOP) Framework (depends on spring-core, spring-beans)
    Define this if you use Spring AOP APIs (org.springframework.aop.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-aop</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Application Context (depends on spring-core, spring-expression, spring-aop, spring-beans)
    This is the central artifact for Spring's Dependency Injection Container and is generally always 
    Defined-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Various Application Context utilities, including EhCache, JavaMail, Quartz, and Freemarker integration
    Define this if you need any of these integrations-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context-support</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Transaction Management Abstraction (depends on spring-core, spring-beans, spring-aop, spring-context)
    Define this if you use Spring Transactions or DAO Exception Hierarchy(org.springframework.transaction.*/org.springframework.dao.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-tx</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--JDBC Data Access Library (depends on spring-core, spring-beans, spring-context, spring-tx)
    Define this if you use Spring's JdbcTemplate API (org.springframework.jdbc.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Object-to-Relation-Mapping (ORM) integration with Hibernate, JPA, and iBatis.(depends on spring-core, spring-beans, spring-context, spring-tx)
    Define this if you need ORM (org.springframework.orm.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-orm</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Object-to-XML Mapping (OXM) abstraction and integration with JAXB, JiBX, Castor, XStream, and XML Beans.(depends on spring-core, spring-beans, spring-context)
    Define this if you need OXM (org.springframework.oxm.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-oxm</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Web application development utilities applicable to both Servlet and Portlet Environments(depends on spring-core, spring-beans, spring-context)
    Define this if you use Spring MVC, or wish to use Struts, JSF, or another web framework with Spring (org.springframework.web.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Spring MVC for Servlet Environments (depends on spring-core, spring-beans, spring-context, spring-web)
    Define this if you use Spring MVC with a Servlet Container such as Apache Tomcat (org.springframework.web.servlet.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Spring MVC for Portlet Environments (depends on spring-core, spring-beans, spring-context, spring-web)
    Define this if you use Spring MVC with a Portlet Container (org.springframework.web.portlet.*)-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc-portlet</artifactId>
    <version>${org.springframework.version}</version>
</dependency>
<!--Support for testing Spring applications with tools such as JUnit and TestNGThis artifact is generally always 
    Defined with a 'test' scope for the integration testing framework and unit testing stubs-->
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-test</artifactId>
    <version>${org.springframework.version}</version>
    <scope>test</scope>
</dependency>

<!-- Begining of Java Standard Tag Libraries -->
 <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <version>1.1.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>standard</artifactId>
        <scope>runtime</scope>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>c</artifactId>
        <version>1.1.1</version>
        <scope>runtime</scope>
        <type>tld</type>
    </dependency>
    <dependency>
        <groupId>taglibs</groupId>
        <artifactId>fmt</artifactId>
        <version>1.1.1</version>
        <scope>runtime</scope>
        <type>tld</type>
    </dependency>
<!-- End of Java Standard Tag Libraries -->


 <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <!-- END OF FULL SPRING 3 DEPENDENCES -->

答案 2 :(得分:0)

它与您的错误无关,但我在您的配置中缺少的是<context:component-scan base-package="..."/>

并且更喜欢使用<mvc:annotation-driven .../>。它不会与<tx:annotation-driven .../><task:annotation-driven />混淆。

答案 3 :(得分:0)

不幸的是,我似乎无法在Eclipse 3.6中实现它。然而,我已经在Spring Tool Suite v2.5.0.M3(http://www.springsource.com/products/springsource-google-download)中了解它 - 如果你检查他们的XML目录,他们确实是几十个可能否定的条目使用vanilla Eclipse而不是STS的价值。如果您正在学习Spring并且由于缺乏入门文档而感到困惑,您可能需要尝试使用Spring Roo,我个人用它来获取Spring MVC项目 - 如果您愿意,可以在之后禁用它。

查看MVC Showcase视频(http://s3.springsource.org/MVC/mvc-showcase-screencast.mov),其中显示将MVC Showcase加载到STS中。请注意,唯一可以修复Eclipse错误的版本(运行时无处不在)是v2.5.0.M3 - 只需确保将展示代码签出到该STS版本的新工作区中。

希望这有帮助。