If I have a @Transactional -annotation on a private method in a Spring bean, does the annotation have any effect?
If the @Transactional
annotation is on a public method, it works and open a transaction.
public class Bean {
public void doStuff() {
doPrivateStuff();
}
@Transactional
private void doPrivateStuff() {
}
}
...
Bean bean = (Bean)appContext.getBean("bean");
bean.doStuff();
Best Answer
The answer your question is no -
@Transactional
will have no effect if used to annotate private methods. The proxy generator will ignore them.This is documented in Spring Manual chapter 10.5.6: