What happen of a class annotated with @Transactional
6563 단어 springframeworkspring
Proxy class is created when class is annotated with @Transactional
In my notice board example application , class info.saladlam.example.spring.noticeboard.service.MessageServiceImpl is annotated with @Transactional . When bean factory processes this class, proxy instance of this classa with set is created. You may view the actual instance of MessageService from Eclipse's debugger.

Function of TransactionInterceptor
Below is code from method org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(Method, Class, InvocationCallback).
// ...
// If the transaction attribute is null, the method is non-transactional.
TransactionAttributeSource tas = getTransactionAttributeSource();
final TransactionAttribute txAttr = (tas != null ? tas.getTransactionAttribute(method, targetClass) : null);
final org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(Method, Class<?>, InvocationCallback) tm = determineTransactionManager(txAttr);
final String joinpointIdentification = methodIdentification(method, targetClass, txAttr);
if (txAttr == null || !(tm instanceof CallbackPreferringPlatformTransactionManager)) {
// Standard transaction demarcation with getTransaction and commit/rollback calls.
TransactionInfo txInfo = createTransactionIfNecessary(tm, txAttr, joinpointIdentification);
Object retVal;
try {
// This is an around advice: Invoke the next interceptor in the chain.
// This will normally result in a target object being invoked.
retVal = invocation.proceedWithInvocation();
}
catch (Throwable ex) {
// target invocation exception
completeTransactionAfterThrowing(txInfo, ex);
throw ex;
}
finally {
cleanupTransactionInfo(txInfo);
}
commitTransactionAfterReturning(txInfo);
return retVal;
}
// ...
When program executes to
retVal = invocation.proceedWithInvocation();
method of info.saladlam.example.spring.noticeboard.service.MessageServiceImpl is called.
Function of PlatformTransactionManager
In Spring Framework context there is a singleton PlatformTransactionManager instance. In this application, the implementation is org.springframework.jdbc.datasource.DataSourceTransactionManager. This class is for handle all transaction action happened.
Reference
이 문제에 관하여(What happen of a class annotated with @Transactional), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/saladlam/items/4118c228dd23e4dff2e1
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Reference
이 문제에 관하여(What happen of a class annotated with @Transactional), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/saladlam/items/4118c228dd23e4dff2e1텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)