Package org.onebusaway.container.spring
Class DependencyConfigurer
- java.lang.Object
-
- org.springframework.core.io.support.PropertiesLoaderSupport
-
- org.springframework.beans.factory.config.PropertyResourceConfigurer
-
- org.onebusaway.container.spring.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.PropertyResourceConfigurerA SpringBeanFactoryPostProcessorthat 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 thedepends-onattribute 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 HibernateSessionFactorythat uses an EhCacheCacheManagerto manage the second-level cache, as defined in theorg/onebusaway/container/application-context-caching.xmlandorg/onebusaway/container/application-context-hibernate.xmlapplication 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 withEhCacheFactoryBean, but they need to be instantiated before theSessionFactory, as the session factory will query theCacheManagerfor cache entries on creation. To ensure that these cache factories are instantiated before the session factory, and we can't set thedepends-onfor the session factory in the config, we use theDependencyConfigurerto manipulate the dependency relationship directly. To useDependencyConfigurer, 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:
This would make the bean "beanA" depend on beans "beanB" and "beanC".beanB,beanC - Author:
- bdferris
-
-
Constructor Summary
Constructors Constructor Description DependencyConfigurer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidprocessKey(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, String beanName, String property)protected voidprocessProperties(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
-
-
-
-
Method Detail
-
processProperties
protected void processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Properties props) throws org.springframework.beans.BeansException- Specified by:
processPropertiesin classorg.springframework.beans.factory.config.PropertyResourceConfigurer- Throws:
org.springframework.beans.BeansException
-
-