1. Add @EnableTransactionManagement to the startup class
2. Add @Transactional on the method / class that needs to add a transaction
Precautions:
Do not catch exceptions in the method of adding transactions, otherwise you cannot roll back. The correct approach is to throw the exception and handle the exception where the method is called