Skip to content

Commit 6ce2eb9

Browse files
committed
EhCacheFactoryBean calls CacheManager.addCache before setStatisticsEnabled
Issue: SPR-11080 Issue: SPR-11092
1 parent 6224ddd commit 6ce2eb9

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

spring-context-support/src/main/java/org/springframework/cache/ehcache/EhCacheFactoryBean.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,7 @@ public void afterPropertiesSet() throws CacheException, IOException {
321321
// create one on the fly.
322322
Ehcache rawCache;
323323
boolean cacheExists = this.cacheManager.cacheExists(this.cacheName);
324+
324325
if (cacheExists) {
325326
if (logger.isDebugEnabled()) {
326327
logger.debug("Using existing EhCache cache region '" + this.cacheName + "'");
@@ -339,6 +340,12 @@ public void afterPropertiesSet() throws CacheException, IOException {
339340
rawCache.getCacheEventNotificationService().registerListener(listener);
340341
}
341342
}
343+
344+
// Needs to happen after listener registration but before setStatisticsEnabled
345+
if (!cacheExists) {
346+
this.cacheManager.addCache(rawCache);
347+
}
348+
342349
if (this.statisticsEnabled) {
343350
rawCache.setStatisticsEnabled(true);
344351
}
@@ -349,9 +356,6 @@ public void afterPropertiesSet() throws CacheException, IOException {
349356
rawCache.setDisabled(true);
350357
}
351358

352-
if (!cacheExists) {
353-
this.cacheManager.addCache(rawCache);
354-
}
355359
Ehcache decoratedCache = decorateCache(rawCache);
356360
if (decoratedCache != rawCache) {
357361
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);

0 commit comments

Comments
 (0)