ehCache and Spring MVC Error with HIbernate
I keep getting this error while setting up ehcache in Spring MVC.
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'com.googlecode.ehcache.annotations.config.internalEhCacheEvictionTask': Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: net.sf.ehcache.CacheManager.getName()Ljava/lang/String;
Below is my setup, and I am using hibernate 3.2.7.GA
<ehcache:config cache-manager="ehCacheManager">
<ehcache:evict-expired-elements interval="60" />
</ehcache:config>
<beans:bean id="ehCacheManager" class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean">
开发者_如何学Python <beans:property name="configLocation" value="/WEB-INF/spring/ehcache.xml"/>
</beans:bean>
Pom.xml
<dependency>
<groupId>com.googlecode.ehcache-spring-annotations</groupId>
<artifactId>ehcache-spring-annotations</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>2.3.2</version>
<type>pom</type>
</dependency>
</dependencies>
<repositories>
<repository>
<id>terracotta-releases</id>
<url>http://www.terracotta.org/download/reflector/releases</url>
<releases><enabled>true</enabled></releases>
<snapshots><enabled>false</enabled></snapshots>
</repository>
The zip file of ehcache-spring-annotations containing the dependencies, downloaded on the project web site, contains ehcache-core version 2.2.0. You're using 2.3.2. There might be an incompatibility between those versions.
Got it working by using an exclude, so yes there was a clash issue.
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>${org.hibernate.commons.annotations-version}</version>
<exclusions>
<exclusion>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
</exclusion>
</exclusions>
</dependency>
精彩评论