Class BeanfactoryDataSourceLookup
java.lang.Object
org.springframework.jdbc.datasource.lookup.BeanfactoryDataSourceLookup
- All Implemented Interfaces:
Aware, BeanfactoryAware, DataSourceLookup
public class BeanfactoryDataSourceLookup
extends Object
implements DataSourceLookup, BeanfactoryAware
DataSourceLookup implementation based on a Spring Beanfactory.
Will lookup Spring managed beans identified by bean name,
expecting them to be of type javax.sql.DataSource.
- Since:
- 2.0
- Author:
- Costin Leau, Juergen Hoeller
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionCreate a new instance of theBeanfactoryDataSourceLookupclass.BeanfactoryDataSourceLookup(Beanfactory beanfactory) Create a new instance of theBeanfactoryDataSourceLookupclass. -
Method Summary
Modifier and TypeMethodDescriptiongetDataSource(String dataSourceName) Retrieve the DataSource identified by the given name.voidsetBeanfactory(Beanfactory beanfactory) Callback that supplies the owning factory to a bean instance.
-
Constructor Details
-
BeanfactoryDataSourceLookup
public BeanfactoryDataSourceLookup()Create a new instance of theBeanfactoryDataSourceLookupclass.The Beanfactory to access must be set via
setBeanfactory.- See Also:
-
BeanfactoryDataSourceLookup
Create a new instance of theBeanfactoryDataSourceLookupclass.Use of this constructor is redundant if this object is being created by a Spring IoC container, as the supplied
Beanfactorywill be replaced by theBeanfactorythat creates it (c.f. theBeanfactoryAwarecontract). So only use this constructor if you are using this class outside the context of a Spring IoC container.- Parameters:
beanfactory- the bean factory to be used to lookupDataSources
-
-
Method Details
-
setBeanfactory
Description copied from interface:BeanfactoryAwareCallback that supplies the owning factory to a bean instance.Invoked after the population of normal bean properties but before an initialization callback such as
InitializingBean.afterPropertiesSet()or a custom init-method.- Specified by:
setBeanfactoryin interfaceBeanfactoryAware- Parameters:
beanfactory- owning Beanfactory (nevernull). The bean can immediately call methods on the factory.- See Also:
-
getDataSource
Description copied from interface:DataSourceLookupRetrieve the DataSource identified by the given name.- Specified by:
getDataSourcein interfaceDataSourceLookup- Parameters:
dataSourceName- the name of the DataSource- Returns:
- the DataSource (never
null) - Throws:
DataSourceLookupfailureException- if the lookup failed
-