Top Description Fields Constructors Methods
org.springframework.jdbc.datasource.lookup

public Class BeanFactoryDataSourceLookup

extends Object
implements DataSourceLookup, BeanFactoryAware
Class Inheritance
All Implemented Interfaces
org.springframework.beans.factory.BeanFactoryAware, org.springframework.beans.factory.Aware, org.springframework.jdbc.datasource.lookup.DataSourceLookup
Imports
javax.sql.DataSource, org.springframework.beans.BeansException, org.springframework.beans.factory.BeanFactory, .BeanFactoryAware, org.springframework.lang.Nullable, org.springframework.util.Assert

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.

Authors
Costin Leau, Juergen Hoeller
Since
2.0
See Also
org.springframework.beans.factory.BeanFactory

Field Summary

Modifier and TypeField and Description
private BeanFactory

Constructor Summary

AccessConstructor and Description
public
BeanFactoryDataSourceLookup()

Create a new instance of the BeanFactoryDataSourceLookup class.

public
BeanFactoryDataSourceLookup(BeanFactory
the bean factory to be used to lookup DataSources
beanFactory
)

Create a new instance of the BeanFactoryDataSourceLookup class.

Method Summary

Modifier and TypeMethod and Description
public DataSource
getDataSource(String
the name of the DataSource
dataSourceName
)

Implements org.springframework.jdbc.datasource.lookup.DataSourceLookup.getDataSource.

Retrieve the DataSource identified by the given name.

public void
setBeanFactory(BeanFactory
owning BeanFactory (never null). The bean can immediately call methods on the factory.
beanFactory
)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback that supplies the owning factory to a bean instance.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanFactoryback to summary
private BeanFactory beanFactory
Annotations
@Nullable

Constructor Detail

BeanFactoryDataSourceLookupback to summary
public BeanFactoryDataSourceLookup()

Create a new instance of the BeanFactoryDataSourceLookup class.

The BeanFactory to access must be set via setBeanFactory.

See Also
setBeanFactory
BeanFactoryDataSourceLookupback to summary
public BeanFactoryDataSourceLookup(BeanFactory beanFactory)

Create a new instance of the BeanFactoryDataSourceLookup 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 the BeanFactory that creates it (c.f. the BeanFactoryAware contract). So only use this constructor if you are using this class outside the context of a Spring IoC container.

Parameters
beanFactory:BeanFactory

the bean factory to be used to lookup DataSources

Method Detail

getDataSourceback to summary
public DataSource getDataSource(String dataSourceName) throws DataSourceLookupFailureException

Implements org.springframework.jdbc.datasource.lookup.DataSourceLookup.getDataSource.

Doc from org.springframework.jdbc.datasource.lookup.DataSourceLookup.getDataSource.

Retrieve the DataSource identified by the given name.

Parameters
dataSourceName:String

the name of the DataSource

Returns:DataSource

the DataSource (never null)

Annotations
@Override
Exceptions
DataSourceLookupFailureException:
if the lookup failed
setBeanFactoryback to summary
public void setBeanFactory(BeanFactory beanFactory)

Implements org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Doc from org.springframework.beans.factory.BeanFactoryAware.setBeanFactory.

Callback 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.

Parameters
beanFactory:BeanFactory

owning BeanFactory (never null). The bean can immediately call methods on the factory.

Annotations
@Override