public class

BeanFactoryDataSourceLookup

extends Object
implements BeanFactoryAware DataSourceLookup
java.lang.Object
   ↳ org.springframework.jdbc.datasource.lookup.BeanFactoryDataSourceLookup

Class Overview

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.

See Also

Summary

Public Constructors
BeanFactoryDataSourceLookup()
Create a new instance of the BeanFactoryDataSourceLookup class.
BeanFactoryDataSourceLookup(BeanFactory beanFactory)
Create a new instance of the BeanFactoryDataSourceLookup class.
Public Methods
DataSource getDataSource(String dataSourceName)
Retrieve the DataSource identified by the given name.
void setBeanFactory(BeanFactory beanFactory)
Callback that supplies the owning factory to a bean instance.
[Expand]
Inherited Methods
From class java.lang.Object
From interface org.springframework.beans.factory.BeanFactoryAware
From interface org.springframework.jdbc.datasource.lookup.DataSourceLookup

Public Constructors

public BeanFactoryDataSourceLookup ()

Create a new instance of the BeanFactoryDataSourceLookup class.

The BeanFactory to access must be set via setBeanFactory.

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 the bean factory to be used to lookup DataSources

Public Methods

public DataSource getDataSource (String dataSourceName)

Retrieve the DataSource identified by the given name.

Parameters
dataSourceName the name of the DataSource
Returns
  • the DataSource (never null)

public void setBeanFactory (BeanFactory beanFactory)

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 afterPropertiesSet() or a custom init-method.

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