spring-context

org.springframework.cache.ehcache
Class EhCacheManagerFactoryBean

java.lang.Object
  extended by org.springframework.cache.ehcache.EhCacheManagerFactoryBean
All Implemented Interfaces:
org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.FactoryBean<net.sf.ehcache.CacheManager>, org.springframework.beans.factory.InitializingBean

public class EhCacheManagerFactoryBean
extends java.lang.Object
implements org.springframework.beans.factory.FactoryBean<net.sf.ehcache.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 3.0, Spring's EHCache support requires EHCache 1.3 or higher.

Since:
1.1.1
Author:
Dmitriy Kopylenko, Juergen Hoeller
See Also:
setConfigLocation(org.springframework.core.io.Resource), setShared(boolean), EhCacheFactoryBean, CacheManager

Field Summary
protected  org.apache.commons.logging.Log logger
           
 
Constructor Summary
EhCacheManagerFactoryBean()
           
 
Method Summary
 void afterPropertiesSet()
           
 void destroy()
           
 net.sf.ehcache.CacheManager getObject()
           
 java.lang.Class<? extends net.sf.ehcache.CacheManager> getObjectType()
           
 boolean isSingleton()
           
 void setCacheManagerName(java.lang.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 VM level) or independent (typically local within the application).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

protected final org.apache.commons.logging.Log logger
Constructor Detail

EhCacheManagerFactoryBean

public EhCacheManagerFactoryBean()
Method Detail

setConfigLocation

public void setConfigLocation(org.springframework.core.io.Resource configLocation)
Set the location of the EHCache config file. A typical value is "/WEB-INF/ehcache.xml".

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).

See Also:
CacheManager.create(java.io.InputStream), CacheManager.CacheManager(java.io.InputStream)

setShared

public void setShared(boolean shared)
Set whether the EHCache CacheManager should be shared (as a singleton at the VM level) or independent (typically local within the application). Default is "false", creating an independent instance.

See Also:
CacheManager.create(), CacheManager.CacheManager()

setCacheManagerName

public void setCacheManagerName(java.lang.String cacheManagerName)
Set the name of the EHCache CacheManager (if a specific name is desired).

See Also:
CacheManager.setName(String)

afterPropertiesSet

public void afterPropertiesSet()
                        throws java.io.IOException,
                               net.sf.ehcache.CacheException
Specified by:
afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
Throws:
java.io.IOException
net.sf.ehcache.CacheException

getObject

public net.sf.ehcache.CacheManager getObject()
Specified by:
getObject in interface org.springframework.beans.factory.FactoryBean<net.sf.ehcache.CacheManager>

getObjectType

public java.lang.Class<? extends net.sf.ehcache.CacheManager> getObjectType()
Specified by:
getObjectType in interface org.springframework.beans.factory.FactoryBean<net.sf.ehcache.CacheManager>

isSingleton

public boolean isSingleton()
Specified by:
isSingleton in interface org.springframework.beans.factory.FactoryBean<net.sf.ehcache.CacheManager>

destroy

public void destroy()
Specified by:
destroy in interface org.springframework.beans.factory.DisposableBean

spring-context