2
<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"
    xmlns:aop="http://www.springframework.org/schema/aop"

    xsi:schemaLocation="
                        http://www.springframework.org/schema/beans 
                        http://www.springframework.org/schema/beans/spring-beans.xsd

    http://www.springframework.org/schema/mvc
                        http://www.springframework.org/schema/mvc/spring-mvc.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/aop 
                        http://www.springframework.org/schema/aop/spring-aop.xsd"
                        >

这是我的模式声明。但是 mvc:annotation-driven 它显示编译时错误。匹配的通配符是严格的,但找不到元素的声明。我无法正确找到问题。所以请帮助找到这个问题。

错误:cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素“mvc:annotation-driven”的声明。你能告诉我有什么问题吗?

4

2 回答 2

4

您的类路径中可能缺少 spring-webmvc-*.jar 文件。

于 2012-07-31T14:33:25.017 回答
0

刚刚创建了这个:

<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"
    xmlns:aop="http://www.springframework.org/schema/aop"

    xsi:schemaLocation="
                    http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd

http://www.springframework.org/schema/mvc
                    http://www.springframework.org/schema/mvc/spring-mvc.xsd
                    http://www.springframework.org/schema/context
                    http://www.springframework.org/schema/context/spring-context.xsd

http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd "

和琐碎的代码

  public static void main(String[] args) {
    System.out.println( new ClassPathXmlApplicationContext("1.xml").getBeanDefinitionCount() );
}

这显示 0 没有错误,所以这实际上是因为根据 @Biju Kunjummen(+1) 缺少 spring-mvc jar

此外,您可能有 2 个不同版本的 spring-mvc ...

于 2012-07-31T14:37:04.367 回答