Class BeanFactoryDataSourceLookup
java.lang.Object
org.springframework.jdbc.datasource.lookup.BeanFactoryDataSourceLookup
- All Implemented Interfaces:
org.springframework.beans.factory.Aware
,org.springframework.beans.factory.BeanFactoryAware
,DataSourceLookup
public class BeanFactoryDataSourceLookup
extends Object
implements DataSourceLookup, org.springframework.beans.factory.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:
-
BeanFactory
-
Constructor Summary
ConstructorDescriptionCreate a new instance of theBeanFactoryDataSourceLookup
class.BeanFactoryDataSourceLookup
(org.springframework.beans.factory.BeanFactory beanFactory) Create a new instance of theBeanFactoryDataSourceLookup
class. -
Method Summary
Modifier and TypeMethodDescriptiongetDataSource
(String dataSourceName) Retrieve the DataSource identified by the given name.void
setBeanFactory
(org.springframework.beans.factory.BeanFactory beanFactory)
-
Constructor Details
-
BeanFactoryDataSourceLookup
public BeanFactoryDataSourceLookup()Create a new instance of theBeanFactoryDataSourceLookup
class.The BeanFactory to access must be set via
setBeanFactory
. -
BeanFactoryDataSourceLookup
public BeanFactoryDataSourceLookup(org.springframework.beans.factory.BeanFactory beanFactory) Create a new instance of theBeanFactoryDataSourceLookup
class.Use of this constructor is redundant if this object is being created by a Spring IoC container, as the supplied
BeanFactory
will be replaced by theBeanFactory
that creates it (c.f. theBeanFactoryAware
contract). 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
public void setBeanFactory(org.springframework.beans.factory.BeanFactory beanFactory) - Specified by:
setBeanFactory
in interfaceorg.springframework.beans.factory.BeanFactoryAware
-
getDataSource
Description copied from interface:DataSourceLookup
Retrieve the DataSource identified by the given name.- Specified by:
getDataSource
in interfaceDataSourceLookup
- Parameters:
dataSourceName
- the name of the DataSource- Returns:
- the DataSource (never
null
) - Throws:
DataSourceLookupFailureException
- if the lookup failed
-