The Spring Framework

org.springframework.jdbc.datasource.lookup
Class BeanFactoryDataSourceLookup

java.lang.Object
  extended by org.springframework.jdbc.datasource.lookup.BeanFactoryDataSourceLookup
All Implemented Interfaces:
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:
BeanFactory

Constructor Summary
BeanFactoryDataSourceLookup()
          Create a new instance of the BeanFactoryDataSourceLookup class.
BeanFactoryDataSourceLookup(BeanFactory beanFactory)
          Create a new instance of the BeanFactoryDataSourceLookup class.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BeanFactoryDataSourceLookup

public BeanFactoryDataSourceLookup()
Create a new instance of the BeanFactoryDataSourceLookup class.

The BeanFactory to access must be set via setBeanFactory.

See Also:
setBeanFactory(org.springframework.beans.factory.BeanFactory)

BeanFactoryDataSourceLookup

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
Method Detail

setBeanFactory

public void setBeanFactory(BeanFactory beanFactory)
Description copied from interface: BeanFactoryAware
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.

Specified by:
setBeanFactory in interface BeanFactoryAware
Parameters:
beanFactory - owning BeanFactory (never null). The bean can immediately call methods on the factory.
See Also:
BeanInitializationException

getDataSource

public DataSource getDataSource(String dataSourceName)
                         throws DataSourceLookupFailureException
Description copied from interface: DataSourceLookup
Retrieve the DataSource identified by the given name.

Specified by:
getDataSource in interface DataSourceLookup
Parameters:
dataSourceName - the name of the DataSource
Returns:
the DataSource (never null)
Throws:
DataSourceLookupFailureException - if the lookup failed

The Spring Framework

Copyright © 2002-2007 The Spring Framework.