2011-03-25 98 views
0

在Spring MVC中設置ehcache時,我總是收到這個錯誤。ehCache和Spring MVC與HIbernate錯誤

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> 

回答

1

通過使用排除得到它的工作,所以是有一個衝突的問題。

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

的Ehcache彈簧的壓縮文件 - 在項目網站上下載的包含依賴關係的註釋包含ehcache-core版本2.2.0。你正在使用2.3.2。這些版本之間可能存在不兼容。