Skip to content

EhCacheManagerFactoryBean should use net.sf.ehcache.config.ConfigurationFactory set the name of ehcache manager [SPR-9171] #13809

@spring-projects-issues

Description

@spring-projects-issues

王正航 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:

Metadata

Metadata

Assignees

Labels

in: coreIssues in core modules (aop, beans, core, context, expression)type: bugA general bug

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions