现在我的应用程序使用Ehcache,Hibernate 3.3.2GA,Spring 3.2.3.RELEASE。我想配置ehcache,以便缓存的maxBytesLocalDisk为5GB。但它不起作用。搜索原因,我发现在Ehcache2.5中只支持maxBytesLocalDisk。所以我从ehcache 1.2.3迁移到2.5.0。 这是主项目的pom.xml :
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>3.6.3.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>3.3.2.GA</version>
<exclusions>
<!-- Excluding ehCache version 1.2.3 -->
<exclusion>
<artifactId>ehcache</artifactId>
<groupId>net.sf.ehcache</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>ejb3-persistence</artifactId>
<version>3.3.2.Beta1</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>3.3.2.GA</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.5.0</version>
</dependency>
这是cache.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:cache="http://www.springframework.org/schema/cache"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-3.2.xsd">
<cache:annotation-driven cache-manager="cacheManager" />
<bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheCacheManager">
<property name="cacheManager">
<bean class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
<property name="configLocation" value="classpath:ehcache.xml" />
</bean>
</property>
</bean>
</beans>
这是ehcache.xml :
<?xml version="1.0" encoding="UTF-8"?>
<ehcache xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd"
maxBytesLocalHeap="256m">
<diskStore path="/var/cache/tomcat7/ehcache"/>
<defaultCache eternal="false"
overflowToDisk="true"
memoryStoreEvictionPolicy="LFU"
timeToIdleSeconds="0"
timeToLiveSeconds="120" />
<cache name="cache1"
overflowToDisk="true"
maxBytesLocalDisk="5g"
memoryStoreEvictionPolicy="LFU"
timeToIdleSeconds="0"
timeToLiveSeconds="3600" />
</ehcache>
重新启动托管此应用程序的tomcat后,抛出异常:
2014-04-26 08:47:50,211 7 ERROR [org.springframework.web.context.ContextLoader] (RMI TCP Connection(3)-127.0.0.1:) Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'channelServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.cache.CacheManager abc.ChannelServiceImpl.cacheManager; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'cacheManager' defined in ServletContext resource [/WEB-INF/context/cache.xml]: Cannot create inner bean 'org.springframework.cache.ehcache.EhCacheManagerFactoryBean#1f3bccc' of type [org.springframework.cache.ehcache.EhCacheManagerFactoryBean] while setting bean property 'cacheManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.cache.ehcache.EhCacheManagerFactoryBean#1f3bccc' defined in ServletContext resource [/WEB-INF/context/cache.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Error configuring from input stream. Initial cause was null:31: Element <cache> does not allow attribute "maxBytesLocalDisk".
由于我在pom.xml上的设置,我不知道是否发生了这个错误。对这个例外的任何想法?
答案 0 :(得分:1)
我会检查你的依赖树。该错误似乎表明在类路径中仍然存在较旧的Ehcache版本。