Skip to content
Advertisement

SpringBoot – @Transactional – not opening transaction

I am trying to use transaction in SpringBoot app , for some reason it just doesn’t work. Below is the code for the sample app. I have a rest api in MyRestController.java which invokes DBService.hello() method. In hello() method I insert a row into a table using JOOQ. I see transaction is NOT being created , after further debugging I see that DataSourceTransactionManager.doBegin() method is not being invoked, which explains why transaction is not created. Can any one point what is wrong with this simple code?

JavaScript

MyRestController.java

JavaScript

DBService.java

JavaScript

Creation of Beans

JavaScript

Advertisement

Answer

Spring Manual chapter 10.5.6:

Method visibility and @Transactional

When using proxies, you should apply the @Transactional annotation only to methods with public visibility. If you do annotate protected, private or package-visible methods with the @Transactional annotation, no error is raised, but the annotated method does not exhibit the configured transactional settings. Consider the use of AspectJ (see below) if you need to annotate non-public methods.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement