If one Service class has method with @Transactional, then spring will use proxy to handle it. But if one Transactional method call another one
@Transactional
public FeedBackModel getOne() {
///..
return getTwo();
}
@Transactional
public FeedBackModel getTwo() {
return null;
}
like this.
if it is jdk proxy, then second @Transactional will not work. But spring PROPAGATION will handle this correctly. How it works?
If you are trying to commit a transaction in getTwo()
which is called from getOne()
, that will not work, not even when both are @Transactional. Refer to the documentation :
...please do take the Spring team's advice and only annotate concrete classes (and the methods of concrete classes) with the @Transactional annotation.
Note: Since this mechanism is based on proxies, only 'external' method calls coming in through the proxy will be intercepted. This means that 'self-invocation' , ie a method within the target object calling some other method of the target object, won't lead to an actual transaction at runtime even if the invoked method is marked with @Transactional!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.