From 6ce2eb96229d64055450861b8cebddb264a59e1c Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Tue, 3 Dec 2013 01:30:22 +0100 Subject: [PATCH] EhCacheFactoryBean calls CacheManager.addCache before setStatisticsEnabled Issue: SPR-11080 Issue: SPR-11092 --- .../cache/ehcache/EhCacheFactoryBean.java | 10 +++++++--- 1 file changed, 7 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 70dfe2a0f4..cc90f227b2 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 @@ -321,6 +321,7 @@ public class EhCacheFactoryBean implements FactoryBean, BeanNameAware, // create one on the fly. Ehcache rawCache; boolean cacheExists = this.cacheManager.cacheExists(this.cacheName); + if (cacheExists) { if (logger.isDebugEnabled()) { logger.debug("Using existing EhCache cache region '" + this.cacheName + "'"); @@ -339,6 +340,12 @@ public class EhCacheFactoryBean implements FactoryBean, BeanNameAware, rawCache.getCacheEventNotificationService().registerListener(listener); } } + + // Needs to happen after listener registration but before setStatisticsEnabled + if (!cacheExists) { + this.cacheManager.addCache(rawCache); + } + if (this.statisticsEnabled) { rawCache.setStatisticsEnabled(true); } @@ -349,9 +356,6 @@ public class EhCacheFactoryBean implements FactoryBean, BeanNameAware, rawCache.setDisabled(true); } - if (!cacheExists) { - this.cacheManager.addCache(rawCache); - } Ehcache decoratedCache = decorateCache(rawCache); if (decoratedCache != rawCache) { this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);