【发布时间】:2014-06-11 22:10:41
【问题描述】:
现在我的应用程序使用 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 上的设置。关于这个例外的任何想法?
【问题讨论】:
-
你为什么使用hibernate-ehcache mavan?
<session-factory>下的hibernate.cfg.xml中有配置吗? -
@Amogh 我在 hibernate.cfg.xml 中配置方言,连接信息
-
你用过hibernate-ehcache mavan吗?
-
随机的想法,但可以检查你是否真的在使用你认为你使用的 ehcache 版本?从svn.terracotta.org/repo/ehcache/tags/ehcache-core-2.5.0/src/… 的 XSD 中获取 2.5.0 的原因,你应该很好。鉴于该错误,您似乎使用的是旧版本
标签: hibernate exception maven-2 ehcache