cvc-complex-type.2.4.c:匹配的通配符是严格的,但是对于元素'cache:annotation-driven'没有声明。
问题描述:
我目前正在尝试为我的应用程序实现缓存,并且我面临一个错误“cvc-complex-type.2.4.c:匹配通配符是严格的,但是对于元素'cache:annotation-driven'没有声明。”在我的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文件的位置。在您的代码中,您基本上告诉解析器,标识符http://www.springframework.org/schema/tx
的xsd文件位于http://www.springframework.org/schema/cache
,标识符http://www.springframework.org/schema/cache/spring-cache.xsd
的xsd文件位于http://www.springframework.org/schema/tx/spring-tx.xsd
。
啊我看看现在是如何工作的。谢谢您的帮助 :) – Sebastian