-
Notifications
You must be signed in to change notification settings - Fork 38.7k
Description
王正航 opened SPR-9171 and commented
In ehcache 2.5.1, net.sf.ehcache.CacheManager has a method assertNoCacheManagerExistsWithSameName called by constructor, this method keeping a static CACHE_MANAGERS_MAP to prevent two CacheManagers having the same name being constructed. However EhCacheManagerFactoryBean's afterPropertiesSet calls net.sf.ehcache.CacheManager.setName after CacheManager's constructor.
When your project use two CacheManager: one is shared and another is not, the project maybe startup failed, because of the shared CacheManager maybe initialized first, assertNoCacheManagerExistsWithSameName put the shared CacheManager instance into CACHE_MANAGERS_MAP using DEFAULT_NAME (DEFAULT), then the unshared CacheManager will be initialized failed.
In fact, using net.sf.ehcache.config.ConfigurationFactory.parseConfiguration to create a net.sf.ehcache.config.Configuration, then set name to this Configuration, and then using net.sf.ehcache.CacheManager.create(net.sf.ehcache.config.Configuration) or net.sf.ehcache.CacheManager(net.sf.ehcache.config.Configuration) will fix this bug.
Here attach my error log and fixed EhCacheManagerFactoryBean.
Affects: 3.1.1
Attachments:
- EhCacheManagerFactoryBean.java (4.79 kB)
- other.log (12.84 kB)