What mechanisms does Spring Boot provide for transaction management?

Spring Boot provides transaction management primarily through the declarative @Transactional annotation, which automatically wraps a method in a transaction and commits or rolls it back based on the method's outcome.

Key Points: • @Transactional uses AOP proxying, so Spring wraps the annotated method with transaction-start/commit/rollback logic transparently. • By default, it rolls back on unchecked exceptions (RuntimeException) and commits otherwise; rollbackFor can extend this to checked exceptions. • Propagation settings (REQUIRED, REQUIRES_NEW, NESTED, etc.) control how a transactional method behaves when called from within another transaction. • Isolation levels (READ_COMMITTED, SERIALIZABLE, etc.) control how concurrent transactions see each other's uncommitted changes. • Programmatic transaction management (via TransactionTemplate) is also available for cases needing more manual control than the annotation offers. • A key gotcha: @Transactional only works through Spring-managed proxies, so calling an annotated method from within the same class bypasses the proxy and the transaction.

Example: Annotating a fund-transfer method with @Transactional ensures that if the credit step fails after the debit step succeeded, both are rolled back together, leaving account balances consistent rather than partially updated.

Code Example:

@Transactional(propagation = Propagation.REQUIRED, rollbackFor = InsufficientFundsException.class)
public void transfer(Account from, Account to, BigDecimal amount) {
    from.debit(amount);
    to.credit(amount);
}

Interview Tip: A concise interview answer is:

"Spring Boot's main mechanism is the declarative @Transactional annotation, which uses AOP to start, commit, or roll back a transaction around a method automatically. I configure propagation and isolation as needed, and I'm careful that self-invocation within the same class bypasses the proxy, so the annotation silently has no effect there."