DataSourceTransactionManager is Spring's PlatformTransactionManager implementation for a single JDBC DataSource. It begins, commits and rolls back local transactions by binding one JDBC Connection to the current thread, so every JdbcTemplate call and every @Transactional method in the same thread uses that connection and commits or rolls back together.
Use it when you work with plain JDBC, JdbcTemplate, NamedParameterJdbcTemplate or MyBatis against one database. Spring Boot auto-configures it when a DataSource and spring-jdbc are present.
When a transactional method starts, the manager:
DataSource (usually a pool such as HikariCP).TransactionSynchronizationManager.JdbcTemplate, retrieve that same connection through DataSourceUtils.This thread-bound connection is the whole mechanism. If you bypass it by calling dataSource.getConnection() yourself, your code runs outside the transaction.
Spring Boot does this for you, but explicit configuration shows the pieces:
The DataSource given to the manager must be the same instance used by JdbcTemplate. In Spring Boot, @EnableTransactionManagement is applied automatically and you only add a bean when you need a second or customised manager.
Both updates run on one connection. If the method throws a RuntimeException or Error, the manager rolls back and neither update is kept. Checked exceptions do not roll back by default; use @Transactional(rollbackFor = Exception.class) when you want that.
For fine control, use TransactionTemplate, which delegates to the manager:
The manager supports the standard propagation settings, which @Transactional(propagation = ...) selects:
| Propagation | Behaviour |
|---|---|
REQUIRED (default) | Join the current transaction or start one |
REQUIRES_NEW | Suspend the current transaction and use a new connection |
SUPPORTS, NOT_SUPPORTED, NEVER | Run with or without a transaction as named |
NESTED | Use a JDBC savepoint inside the current transaction (needs savepoint support in the driver) |
REQUIRES_NEW needs a second connection from the pool, so a tiny pool can deadlock if all connections are held by outer transactions.
DataSource. A transaction across two databases is not atomic with this manager. Use a JTA manager, or design for eventual consistency (for example with an outbox).JpaTransactionManager, which also exposes the JDBC connection to JdbcTemplate on the same DataSource. Mixing DataSourceTransactionManager with JPA entity managers does not work.@Async methods and virtual threads you start yourself, is not part of the caller's transaction.@Transactional("ordersTxManager").@Transactional works through proxies, so self-invocation and non-public methods are not intercepted.Use it for JDBC, JdbcTemplate or MyBatis without JPA. If your application uses JPA or Spring Data JPA, use JpaTransactionManager.
Yes, DataSourceTransactionManagerAutoConfiguration registers one for a single DataSource when no other PlatformTransactionManager bean exists.
Common causes are a checked exception without rollbackFor, a swallowed exception, self-invocation, a non-public method, or code that opens its own connection outside the managed one.
No. Reactive stacks (R2DBC) use R2dbcTransactionManager, because a thread-bound connection does not work with reactive pipelines.
DataSourceTransactionManager provides local, thread-bound JDBC transactions for one DataSource. It powers @Transactional and TransactionTemplate with JdbcTemplate, handles commit, rollback, isolation and propagation, and should be replaced by JpaTransactionManager or a distributed approach when you use JPA or span several databases.