Spring-tx-TransactionAnnotationParser介面
阿新 • • 發佈:2021-01-13
技術標籤:Spring
事務註解轉換器
說白了就是該介面的實現會將@Transactional註解轉換成TransactionAttribute
,該介面只有一個抽象方法
@Nullable
TransactionAttribute parseTransactionAnnotation(AnnotatedElement ae);
其中SpringTransactionAnnotationParser類是該介面的實現之一,下面以該類作為演示
import org.springframework.transaction.annotation.Propagation;
import org. springframework.transaction.annotation.Transactional;
@Transactional(propagation = Propagation.REQUIRED)
public class Class01 {
@Transactional(propagation = Propagation.NEVER)
public void m1() {
}
public static void main(String[] args) throws NoSuchMethodException, SecurityException {
SpringTransactionAnnotationParser tap = new SpringTransactionAnnotationParser();
Class<?> clazz = Class01.class;
Method method = Class01.class.getMethod("m1");
TransactionAttribute ta1 = tap.parseTransactionAnnotation(clazz);
TransactionAttribute ta2 = tap.parseTransactionAnnotation(method);
System.out.println(ta1) ;
System.out.println(ta2);
}
}