问题描述
|
在Spring MVC中设置ehcache时,我一直收到此错误。
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;
以下是我的设置,我正在使用休眠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\">
<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>
解决方法
在项目网站上下载的包含依赖项的ehcache-spring-annotations zip文件包含ehcache-core版本2.2.0。您正在使用2.3.2。这些版本之间可能不兼容。
,通过使用排除使其工作,所以是的,存在冲突问题。
<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>