spring-framework / org.springframework.jdbc.datasource / DataSourceTransactionManager / setDataSource

setDataSource

open fun setDataSource(@Nullable dataSource: DataSource): Unit

Set the JDBC DataSource that this instance should manage transactions for.

This will typically be a locally defined DataSource, for example an Apache Commons DBCP connection pool. Alternatively, you can also drive transactions for a non-XA J2EE DataSource fetched from JNDI. For an XA DataSource, use JtaTransactionManager.

The DataSource specified here should be the target DataSource to manage transactions for, not a TransactionAwareDataSourceProxy. Only data access code may work with TransactionAwareDataSourceProxy, while the transaction manager needs to work on the underlying target DataSource. If there's nevertheless a TransactionAwareDataSourceProxy passed in, it will be unwrapped to extract its target DataSource.

The DataSource passed in here needs to return independent Connections. The Connections may come from a pool (the typical case), but the DataSource must not return thread-scoped / request-scoped Connections or the like.

See Also
TransactionAwareDataSourceProxyorg.springframework.transaction.jta.JtaTransactionManager