spring3.1,cache的配置问题

melnnyy 发布于 2012/06/19 17:57
阅读 3K+
收藏 0

我用的是ehcache,本地可以运行,但传到服务器上总是报错:

nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'ehcache'.

这是为什么?

配置文件如下

ehcache的配置文件 
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
 updateCheck="false">
 <diskStore path="${cache.dir}" />

 <defaultCache eternal="false"
   maxElementsInMemory="1000"
   overflowToDisk="false"
   diskPersistent="false"
   timeToIdleSeconds="0"
   timeToLiveSeconds="600"
   memoryStoreEvictionPolicy="LRU" />

 <cache name="testCache"
   eternal="true"
   maxElementsInMemory="100"
   overflowToDisk="false"
   diskPersistent="false"
   memoryStoreEvictionPolicy="LRU" />

</ehcache>

spring的配置文件
<?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:p="http://www.springframework.org/schema/p" xmlns:cache="http://www.springframework.org/schema/cache"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">

<context:annotation-config/>

<context:component-scan base-package="com.test.cache" />

<!-- 缓存注解驱动 -->
<cache:annotation-driven />

<!-- cacheManager工厂类 -->
<bean id="cacheManagerFactory" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"
     p:configLocation="classpath:/ehcache.xml"
     p:shared="false" />

<!-- 声明cacheManager -->
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager" p:cacheManager-ref="cacheManagerFactory"/>

加载中
0
catty
catty

偷懶的做法, 把ehcache.xsd放到同目錄下,然後SchemaLocation的值改一下

<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:noNamespaceSchemaLocation="ehcache.xsd"
 updateCheck="false">

0
y
yugiohboy
${cache.dir} 这个要怎么引用,我在properties文件中指定了cache.dir=D:/abc 但运行时候会产生一个、目录是以${cache.dir}命名,不是D:/abc
返回顶部
顶部