public class EhCacheManagerFactoryBean extends Object implements org.springframework.beans.factory.FactoryBean<CacheManager>, org.springframework.beans.factory.InitializingBean, org.springframework.beans.factory.DisposableBean
FactoryBean
that exposes an EhCache CacheManager
instance (independent or shared), configured from a specified config location.
If no config location is specified, a CacheManager will be configured from "ehcache.xml" in the root of the class path (that is, default EhCache initialization - as defined in the EhCache docs - will apply).
Setting up a separate EhCacheManagerFactoryBean is also advisable when using EhCacheFactoryBean, as it provides a (by default) independent CacheManager instance and cares for proper shutdown of the CacheManager. EhCacheManagerFactoryBean is also necessary for loading EhCache configuration from a non-default config location.
Note: As of Spring 5.0, Spring's EhCache support requires EhCache 2.10 or higher.
setConfigLocation(org.springframework.core.io.Resource)
,
setShared(boolean)
,
EhCacheFactoryBean
,
CacheManager
Constructor and Description |
---|
EhCacheManagerFactoryBean() |
Modifier and Type | Method and Description |
---|---|
void |
afterPropertiesSet() |
void |
destroy() |
CacheManager |
getObject() |
Class<? extends CacheManager> |
getObjectType() |
boolean |
isSingleton() |
void |
setAcceptExisting(boolean acceptExisting)
Set whether an existing EhCache CacheManager of the same name will be accepted
for this EhCacheManagerFactoryBean setup.
|
void |
setCacheManagerName(String cacheManagerName)
Set the name of the EhCache CacheManager (if a specific name is desired).
|
void |
setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the EhCache config file.
|
void |
setShared(boolean shared)
Set whether the EhCache CacheManager should be shared (as a singleton at the
ClassLoader level) or independent (typically local within the application).
|
protected final Log logger
public void setConfigLocation(org.springframework.core.io.Resource configLocation)
Default is "ehcache.xml" in the root of the class path, or if not found, "ehcache-failsafe.xml" in the EhCache jar (default EhCache initialization).
public void setCacheManagerName(String cacheManagerName)
Configuration.setName(String)
public void setAcceptExisting(boolean acceptExisting)
Typically used in combination with "cacheManagerName"
but will simply work with the default CacheManager name if none specified.
All references to the same CacheManager name (or the same default) in the
same ClassLoader space will share the specified CacheManager then.
public void setShared(boolean shared)
NOTE: This feature allows for sharing this EhCacheManagerFactoryBean's
CacheManager with any code calling CacheManager.create()
in the same
ClassLoader space, with no need to agree on a specific CacheManager name.
However, it only supports a single EhCacheManagerFactoryBean involved which will
control the lifecycle of the underlying CacheManager (in particular, its shutdown).
This flag overrides "acceptExisting"
if both are set,
since it indicates the 'stronger' mode of sharing.
public void afterPropertiesSet() throws CacheException
afterPropertiesSet
in interface org.springframework.beans.factory.InitializingBean
CacheException
@Nullable public CacheManager getObject()
getObject
in interface org.springframework.beans.factory.FactoryBean<CacheManager>
public Class<? extends CacheManager> getObjectType()
getObjectType
in interface org.springframework.beans.factory.FactoryBean<CacheManager>
public boolean isSingleton()
isSingleton
in interface org.springframework.beans.factory.FactoryBean<CacheManager>
public void destroy()
destroy
in interface org.springframework.beans.factory.DisposableBean