Class EhCacheFactoryBean

    • Field Detail

      • logger

        protected final Log logger
    • Constructor Detail

      • EhCacheFactoryBean

        public EhCacheFactoryBean()
    • Method Detail

      • setCacheManager

        public void setCacheManager(CacheManager cacheManager)
        Set a CacheManager from which to retrieve a named Cache instance. By default, CacheManager.getInstance() will be called.

        Note that in particular for persistent caches, it is advisable to properly handle the shutdown of the CacheManager: Set up a separate EhCacheManagerFactoryBean and pass a reference to this bean property.

        A separate EhCacheManagerFactoryBean is also necessary for loading EhCache configuration from a non-default config location.

        See Also:
        EhCacheManagerFactoryBean, CacheManager.getInstance()
      • setCacheName

        public void setCacheName(java.lang.String cacheName)
        Set a name for which to retrieve or create a cache instance. Default is the bean name of this EhCacheFactoryBean.
      • setDisabled

        public void setDisabled(boolean disabled)
        Set whether this cache should be marked as disabled.
        See Also:
      • setBeanName

        public void setBeanName(java.lang.String name)
        Description copied from interface: BeanNameAware
        Set the name of the bean in the bean factory that created this bean.

        Invoked after population of normal bean properties but before an init callback such as InitializingBean.afterPropertiesSet() or a custom init-method.

        Specified by:
        setBeanName in interface BeanNameAware
        name - the name of the bean in the factory. Note that this name is the actual bean name used in the factory, which may differ from the originally specified name: in particular for inner bean names, the actual bean name might have been made unique through appending "#..." suffixes. Use the BeanFactoryUtils.originalBeanName(String) method to extract the original bean name (without suffix), if desired.
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws CacheException
        Description copied from interface: InitializingBean
        Invoked by the containing BeanFactory after it has set all bean properties and satisfied BeanFactoryAware, ApplicationContextAware etc.

        This method allows the bean instance to perform validation of its overall configuration and final initialization when all bean properties have been set.

        Specified by:
        afterPropertiesSet in interface InitializingBean
      • createCache

        protected Cache createCache()
        Create a raw Cache object based on the configuration of this FactoryBean.
      • decorateCache

        protected Ehcache decorateCache(Ehcache cache)
        Decorate the given Cache, if necessary.
        cache - the raw Cache object, based on the configuration of this FactoryBean
        the (potentially decorated) cache object to be registered with the CacheManager
      • getObject

        public Ehcache getObject()
        Description copied from interface: FactoryBean
        Return an instance (possibly shared or independent) of the object managed by this factory.

        As with a BeanFactory, this allows support for both the Singleton and Prototype design pattern.

        If this FactoryBean is not fully initialized yet at the time of the call (for example because it is involved in a circular reference), throw a corresponding FactoryBeanNotInitializedException.

        As of Spring 2.0, FactoryBeans are allowed to return null objects. The factory will consider this as normal value to be used; it will not throw a FactoryBeanNotInitializedException in this case anymore. FactoryBean implementations are encouraged to throw FactoryBeanNotInitializedException themselves now, as appropriate.

        Specified by:
        getObject in interface FactoryBean<Ehcache>
        an instance of the bean (can be null)
        See Also:
      • isSingleton

        public boolean isSingleton()
        Description copied from interface: FactoryBean
        Is the object managed by this factory a singleton? That is, will FactoryBean.getObject() always return the same object (a reference that can be cached)?

        NOTE: If a FactoryBean indicates to hold a singleton object, the object returned from getObject() might get cached by the owning BeanFactory. Hence, do not return true unless the FactoryBean always exposes the same reference.

        The singleton status of the FactoryBean itself will generally be provided by the owning BeanFactory; usually, it has to be defined as singleton there.

        NOTE: This method returning false does not necessarily indicate that returned objects are independent instances. An implementation of the extended SmartFactoryBean interface may explicitly indicate independent instances through its SmartFactoryBean.isPrototype() method. Plain FactoryBean implementations which do not implement this extended interface are simply assumed to always return independent instances if the isSingleton() implementation returns false.

        The default implementation returns true, since a FactoryBean typically manages a singleton instance.

        Specified by:
        isSingleton in interface FactoryBean<Ehcache>
        whether the exposed object is a singleton
        See Also:
        FactoryBean.getObject(), SmartFactoryBean.isPrototype()