Java cvc complex type.2.4.c:匹配的通配符是严格的,但是找不到元素';缓存:注释驱动';

Java cvc complex type.2.4.c:匹配的通配符是严格的,但是找不到元素';缓存:注释驱动';,java,spring,caching,Java,Spring,Caching,我目前正在尝试为我的应用程序实现缓存,但我在pom.xml中遇到了一个错误“cvc complex type.2.4.c:匹配的通配符是严格的,但是找不到元素“cache:annotation-driven.”的声明。我有什么遗漏吗 pom.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://

我目前正在尝试为我的应用程序实现缓存,但我在pom.xml中遇到了一个错误“cvc complex type.2.4.c:匹配的通配符是严格的,但是找不到元素“cache:annotation-driven.”的声明。我有什么遗漏吗

pom.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:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx" xmlns:cache="http://www.springframework.org/schema/cache"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
                    http://www.springframework.org/schema/beans/spring-beans.xsd
                    http://www.springframework.org/schema/context 
                    http://www.springframework.org/schema/context/spring-context.xsd
                    http://www.springframework.org/schema/tx
                    http://www.springframework.org/schema/cache
                    http://www.springframework.org/schema/cache/spring-cache.xsd
                    http://www.springframework.org/schema/tx/spring-tx.xsd">

<context:annotation-config />
<context:component-scan base-package="packages path" />

<!-- Enables the caching through annotations -->
<cache:annotation-driven />

<!-- Generic cache manager based on the JDK ConcurrentMap -->
<bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
    <property name="caches">
        <set>
            <bean
                class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean"
                p:name="task" />
        </set>
    </property>
</bean>


您在属性schemaLocation中的顺序是错误的。而不是

xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/cache
                http://www.springframework.org/schema/cache/spring-cache.xsd
                http://www.springframework.org/schema/tx/spring-tx.xsd"
应该是

xsi:schemaLocation="http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans.xsd
                http://www.springframework.org/schema/context 
                http://www.springframework.org/schema/context/spring-context.xsd
                http://www.springframework.org/schema/cache
                http://www.springframework.org/schema/cache/spring-cache.xsd
                http://www.springframework.org/schema/tx
                http://www.springframework.org/schema/tx/spring-tx.xsd"
schemaLocation中的值总是由成对的元素组成。第一个元素表示在xmlns属性中使用的模式标识符,每对中的第二个元素表示xsd文件的位置。在代码中,您基本上告诉解析器,标识符的xsd文件
http://www.springframework.org/schema/tx
位于
http://www.springframework.org/schema/cache
和标识符的xsd文件
http://www.springframework.org/schema/cache/spring-cache.xsd
位于
http://www.springframework.org/schema/tx/spring-tx.xsd