Scaling API-first – The story of a global engineering organization
Spring Transaction
1. Transaction Management in Spring In this chapter, you will learn about the basic concept of transactions and Spring’s capabilitiesin the area of transactionmanagement. Transactionmanagement is an essential technique in enterprise applications to ensure data integrity and consistency. Spring, as an enterprise application framework, defines an abstract layer on top of different transaction management APIs. As an application developer, you can utilize Spring’s transactionmanagementfacilities without having to knowmuch about the underlying transactionmanagement APIs.Like the bean-managed transaction (BMT) and container-managed transaction (CMT) approaches in EJB, Spring supports both programmatic and declarative transactionmanagement.The aimof Spring’s transaction support is to provide an alternative to EJB transactions by adding transaction capabilities to POJOs.Programmatic transactionmanagement is achieved by embedding transactionmanagement code in your businessmethods to control the commit and rollback of transactions. Youusually commit a transaction if amethod completes normally, and roll back a transaction if a method throws certain types of exceptions.With programmatic transactionmanagement, you can further define your own rules to commit and roll back transactions.However, whenmanaging transactions programmatically, you have to include additional transactionmanagement code in each transactional operation. As a result, the boilerplate transaction code is repeated in each of these operations.Moreover, it’s hard for you to enable and disable Transactionmanagement for different applications. If you have a solid understanding of AOP, you should already have noticed that transactionmanagement is a kind of crosscutting concern.