org.onebusaway.container.spring
public class DependencyConfigurer extends org.springframework.beans.factory.config.PropertyResourceConfigurer
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:
This would make the bean "beanA" depend on beans "beanB" and "beanC".beanB,beanC
Constructor and Description |
---|
DependencyConfigurer() |
Modifier and Type | Method and 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) |
convertProperties, convertPropertyValue, getOrder, postProcessBeanFactory, setOrder
protected void processProperties(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, Properties props) throws org.springframework.beans.BeansException
processProperties
in class org.springframework.beans.factory.config.PropertyResourceConfigurer
org.springframework.beans.BeansException
Copyright © 2014 OneBusAway. All Rights Reserved.