导包的时候发现有两个注解
//javax的注解,即jpa的注解
javax.transaction.Transactional
//spring的注解
org.springframework.transaction.annotation.Transactional
观察AnnotationTransactionAttributeSource 类
public AnnotationTransactionAttributeSource(boolean publicMethodsOnly) {
this.publicMethodsOnly = publicMethodsOnly;
this.annotationParsers = new LinkedHashSet<TransactionAnnotationParser>(2);
//添加解析spring @Transactional 注解的解析器
this.annotationParsers.add(new SpringTransactionAnnotationParser());
if (jta12Present) {
//添加解析jpa @Transactional 注解的解析器
this.annotationParsers.add(new JtaTransactionAnnotationParser());
}
if (ejb3Present) {
this.annotationParsers.add(new Ejb3TransactionAnnotationParser());
}
}
综上,本人建议使用spring的@Transactional 注解