Transaction Management in Spring Boot

--

Hello everyone,

Transaction management is one of the difficult features to understand for the developers and hence I decided to write on this topic. Let us take a look at how the Spring framework does transaction management.

There are 2 types of transaction management namely

  1. Declarative
  2. Programmatic

1. Declarative Transaction Management

Declarative transaction management is the most widely used method in which the developers tell the framework to handle the transactions. This can be achieved in 2 ways ie. through XML configurations or through annotations

Now, let us focus only on the annotation part.

We need to include 2 annotations for this to take effect

  1. @EnableTransactionManagement annotation is usually on the main class. Adding @EnableTransactionManagement annotation creates a PlatformTransactionManager for you — with its JDBC auto-configurations.
@SpringBootApplication
@EnableTransactionManagement
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}

2. @Transactional annotation on a service class or a method

Using Transactional annotation on the class level marks the class as transactional

@Transactional
public…

--

--

Dineshchandgr - A Top writer in Technology
Javarevisited

Principal Software Engineer and Technical Lead focussed on Backend Engineering who likes to upgrade the tech skills and share knowledge to the community