2010-09-22 60 views
3

我正在尝试在此处构建mvc-showcase示例link<mvc:resources> type not resolved

但我提示以下错误:

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element '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和我使用的弹簧3.0.4版本(因为我使用的是项目link中给出的相同的pom.xml)

+0

我无法正确格式化代码。有人请纠正它。编辑了5次,但无法更正 – javanoob 2010-09-22 13:55:03

+1

这可能是因为Eclipses的XML Catalog未配置为针对JAR中嵌入的3.0.4架构进行验证,或者您正在使用Spring Catalog的版本,该版本的XML Catalog使用的是Spring jar包含在STS 2.3.3.M3的插件v3.0.3中。你在使用vanilla Eclipse还是Spring Tool Suite?让我知道这个版本,我会看看。 – delimited 2010-09-22 20:08:02

+0

我正在使用eclipse和春天版本3.0.4 – javanoob 2010-09-23 06:44:55

回答

0

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

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

希望这会有所帮助。

+0

分隔,我下载了spring工具套件并且能够在那里运行应用程序...看来eclipse有一些问题 – javanoob 2010-09-25 12:55:19

0

这与您的错误无关,但是我错过了<context:component-scan base-package="..."/>在您的配置。

宁愿使用<mvc:annotation-driven .../>。它不会与<tx:annotation-driven .../><task:annotation-driven />混淆。

4

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

干杯

1

我与标签同样的问题。问题是你的春季版本@Drolyk悲伤是3.0.4或更高版本可用,所以我会给你我的依赖关系,我相信,如果你使用它们U将解决这个问题:

<!-- 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 --> 
相关问题