Skip to content

Commit 6c1f62b

Browse files
committed
EhCacheFactoryBean calls CacheManager.addCache before setStatisticsEnabled
Issue: SPR-11080 Issue: SPR-11092 (cherry picked from commit 6ce2eb9)
1 parent f5a310a commit 6c1f62b

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
@@ -234,6 +234,7 @@ public void afterPropertiesSet() throws CacheException, IOException {
234234
// Fetch cache region: If none with the given name exists, create one on the fly.
235235
Ehcache rawCache;
236236
boolean cacheExists = this.cacheManager.cacheExists(cacheName);
237+
237238
if (cacheExists) {
238239
if (logger.isDebugEnabled()) {
239240
logger.debug("Using existing EhCache cache region '" + cacheName + "'");
@@ -253,6 +254,12 @@ public void afterPropertiesSet() throws CacheException, IOException {
253254
rawCache.getCacheEventNotificationService().registerListener(listener);
254255
}
255256
}
257+
258+
// Needs to happen after listener registration but before setStatisticsEnabled
259+
if (!cacheExists) {
260+
this.cacheManager.addCache(rawCache);
261+
}
262+
256263
if (this.statisticsEnabled) {
257264
rawCache.setStatisticsEnabled(true);
258265
}
@@ -263,9 +270,6 @@ public void afterPropertiesSet() throws CacheException, IOException {
263270
rawCache.setDisabled(true);
264271
}
265272

266-
if (!cacheExists) {
267-
this.cacheManager.addCache(rawCache);
268-
}
269273
Ehcache decoratedCache = decorateCache(rawCache);
270274
if (decoratedCache != rawCache) {
271275
this.cacheManager.replaceCacheWithDecoratedCache(rawCache, decoratedCache);

0 commit comments

Comments
 (0)