Class DependencyConfigurer

  • All Implemented Interfaces:
    org.springframework.beans.factory.config.BeanFactoryPostProcessor, org.springframework.core.Ordered, org.springframework.core.PriorityOrdered

    public class DependencyConfigurer
    extends org.springframework.beans.factory.config.PropertyResourceConfigurer
    A Spring BeanFactoryPostProcessor that can set bean dependencies to adjust bean creation order. Typically, you don't need to set bean dependencies directly, as Spring figures it out from bean references in your application context in bean property setters. Sometimes, you need to set a dependency that Spring cannot detect on its own, and you'd do this by adjusting the depends-on attribute of a bean defintion. While that works for most cases, we've managed to find a case where that doesn't work. To give a specific example, we're creating a Hibernate SessionFactory that uses an EhCache CacheManager to manage the second-level cache, as defined in the org/onebusaway/container/application-context-caching.xml and org/onebusaway/container/application-context-hibernate.xml application context config files. A number of modules import these configs and add additional Hibernate entity classes and mappings. These modules would also like to add EhCache second-level caches for these entity classes. These caches can be created with EhCacheFactoryBean, but they need to be instantiated before the SessionFactory, as the session factory will query the CacheManager for cache entries on creation. To ensure that these cache factories are instantiated before the session factory, and we can't set the depends-on for the session factory in the config, we use the DependencyConfigurer to manipulate the dependency relationship directly. To use DependencyConfigurer, set a "properties" property for the bean definition where the each property key is a bean name and each property value is a list of dependent bean names separated by commas. So for example:
     
       
         
         beanB,beanC
        
       
     
     
    This would make the bean "beanA" depend on beans "beanB" and "beanC".
    Author:
    bdferris
    • Field Summary

      • Fields inherited from class org.springframework.core.io.support.PropertiesLoaderSupport

        localOverride, localProperties, logger
      • Fields inherited from interface org.springframework.core.Ordered

        HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void processKey​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String beanName, String property)  
      protected void processProperties​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Properties props)  
      • Methods inherited from class org.springframework.beans.factory.config.PropertyResourceConfigurer

        convertProperties, convertProperty, convertPropertyValue, getOrder, postProcessBeanFactory, setOrder
      • Methods inherited from class org.springframework.core.io.support.PropertiesLoaderSupport

        loadProperties, mergeProperties, setFileEncoding, setIgnoreResourceNotFound, setLocalOverride, setLocation, setLocations, setProperties, setPropertiesArray, setPropertiesPersister
    • Constructor Detail

      • DependencyConfigurer

        public DependencyConfigurer()
    • Method Detail

      • processProperties

        protected void processProperties​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                         Properties props)
                                  throws org.springframework.beans.BeansException
        Specified by:
        processProperties in class org.springframework.beans.factory.config.PropertyResourceConfigurer
        Throws:
        org.springframework.beans.BeansException
      • processKey

        protected void processKey​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                  String beanName,
                                  String property)