From a3df311bb5f7ad7e18212f57192a70b9de8c158c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Sat, 14 Sep 2013 07:05:24 +0200 Subject: [PATCH] EhCacheFactoryBean calls addCache after listener registration Issue: SPR-10904 --- .../springframework/cache/ehcache/EhCacheFactoryBean.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java index 665e973176..2ebb09e258 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java +++ b/spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java @@ -231,7 +231,8 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea // Fetch cache region: If none with the given name exists, create one on the fly. Ehcache rawCache; - if (this.cacheManager.cacheExists(cacheName)) { + boolean cacheExists = this.cacheManager.cacheExists(cacheName); + if (cacheExists) { if (logger.isDebugEnabled()) { logger.debug("Using existing EhCache cache region '" + cacheName + "'"); } @@ -243,7 +244,6 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea } rawCache = createCache(); rawCache.setBootstrapCacheLoader(this.bootstrapCacheLoader); - this.cacheManager.addCache(rawCache); } if (this.cacheEventListeners != null) { @@ -261,7 +261,9 @@ public class EhCacheFactoryBean extends CacheConfiguration implements FactoryBea rawCache.setDisabled(true); } - // Decorate cache if necessary. + if (!cacheExists) { + this.cacheManager.addCache(rawCache); + } Ehcache decoratedCache = decorateCache(rawCache); if (decoratedCache != rawCache) { this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);