longkid
longkid

Reputation: 21

Exception thrown after customizing ehcache.xml with parameter maxBytesLocalDisk

Right now my application use Ehcache, Hibernate 3.3.2GA, Spring 3.2.3.RELEASE. I want to configure ehcache so that maxBytesLocalDisk of a cache is 5GB. But it does not work. Searching on reason, I found that maxBytesLocalDisk is just supported in Ehcache2.5. So I migrate from ehcache 1.2.3 to 2.5.0. This is pom.xml of main project:

<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>

This is cache.xml file:

<?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>

This is 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>

After restart tomcat which hosts this application, an exception is thrown:

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".

I don't know if this error happened because of my setting on pom.xml. Any idea about this exception?

Upvotes: 2

Views: 1778

Answers (1)

Louis Jacomet
Louis Jacomet

Reputation: 14500

I would check your dependency tree. The error seems to indicate that there is still an older Ehcache version found on the classpath.

Upvotes: 2

Related Questions