Announcement Announcement Module
Collapse
No announcement yet.
EhCacheManagerFactoryBean and JUnit tests Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • EhCacheManagerFactoryBean and JUnit tests

    I'm on Spring 3.1.1 and EhCache 2.6.0. When running my JUnit tests extending AbstractJUnit4SpringContextTests, the first test runs fine, but the second test fails with the following error:

    Caused by: org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'org.springframework.cache.ehcache.EhCacheFactoryB ean#1e34760' defined in class path resource [applicationContext.xml]: Invocation of init method failed; nested exception is net.sf.ehcache.CacheException: Cannot replace com.xxx.MyClass It does not equal the incumbent cache.
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1455)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.doCreateBean(AbstractAu towireCapableBeanFactory.java:519)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:456)
    at org.springframework.beans.factory.support.BeanDefi nitionValueResolver.resolveInnerBean(BeanDefinitio nValueResolver.java:270)
    Caused by: net.sf.ehcache.CacheException: Cannot replace com.xxx.MyClass It does not equal the incumbent cache.
    at net.sf.ehcache.CacheManager.replaceCacheWithDecora tedCache(CacheManager.java:1649)
    at org.springframework.cache.ehcache.EhCacheFactoryBe an.afterPropertiesSet(EhCacheFactoryBean.java:338)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.invokeInitMethods(Abstr actAutowireCapableBeanFactory.java:1514)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.initializeBean(Abstract AutowireCapableBeanFactory.java:1452)

    The relevant bean in my app context is as follows:

    <bean id="cacheManager" class="org.springframework.cache.ehcache.EhCacheMa nagerFactoryBean">
    <property name="configLocation" value="classpath:ehcache-application.xml" />
    <property name="cacheManagerName" value="cacheManager" />
    <property name="shared" value="true" />
    </bean>

    For now, I have locally modified EhCacheManagerFactoryBean.afterPropertiesSet() to simply return immediately, if CacheManager.getCacheManager returns an existing cache manager of the same name.

    I'm sure there must be a better approach than resorting to this... when the app context shuts down between unit tests, should I be doing something to remove all caches from each cache manager? (evidently one of the previous caches com.xxx.MyClass is still there from the previous run).

  • #2
    In my case this error only occurs if I'm using the decoration feature of the EhCacheFactoryBean (e.g. set blocking to true). I'm doing the decoration on my own now (with net.sf.ehcache.constructs.blocking.BlockingCache) to avoid it.

    Comment

    Working...
    X