下面列出了怎么用org.springframework.transaction.annotation.AnnotationTransactionAttributeSource的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Note: resolution does not occur. Thus we can't make a class transactional if
* it implements a transactionally annotated interface. This behaviour could only
* be changed in AbstractFallbackTransactionAttributeSource in Spring proper.
*/
public void testDoesNotResolveTxAnnotationOnMethodFromClassImplementingAnnotatedInterface() throws Exception {
AnnotationTransactionAttributeSource atas = new AnnotationTransactionAttributeSource();
Method m = ImplementsAnnotatedInterface.class.getMethod("echo", Throwable.class);
TransactionAttribute ta = atas.getTransactionAttribute(m, ImplementsAnnotatedInterface.class);
assertNull(ta);
}
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
String[] beanNameArray = beanFactory.getBeanDefinitionNames();
for (int i = 0; i < beanNameArray.length; i++) {
String beanName = beanNameArray[i];
BeanDefinition beanDef = beanFactory.getBeanDefinition(beanName);
String beanClassName = beanDef.getBeanClassName();
if (org.springframework.transaction.interceptor.TransactionProxyFactoryBean.class.getName().equals(beanClassName)) {
throw new FatalBeanException(String.format(
"Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).",
beanName));
}
if (org.springframework.transaction.interceptor.TransactionInterceptor.class.getName().equals(beanClassName)) {
boolean errorExists = true;
MutablePropertyValues mpv = beanDef.getPropertyValues();
PropertyValue pv = mpv.getPropertyValue("transactionAttributeSource");
Object value = pv == null ? null : pv.getValue();
if (value != null && RuntimeBeanReference.class.isInstance(value)) {
RuntimeBeanReference reference = (RuntimeBeanReference) value;
BeanDefinition refBeanDef = beanFactory.getBeanDefinition(reference.getBeanName());
String refBeanClassName = refBeanDef.getBeanClassName();
errorExists = AnnotationTransactionAttributeSource.class.getName().equals(refBeanClassName) == false;
}
if (errorExists) {
throw new FatalBeanException(String.format(
"Declaring transactions by configuration is not supported yet, please use annotations to declare transactions(beanId= %s).",
beanName));
} // end-if (errorExists)
}
} // end-for (int i = 0; i < beanNameArray.length; i++)
}
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionAttributeSource transactionAttributeSource() {
return new AnnotationTransactionAttributeSource();
}
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionAttributeSource transactionAttributeSource() {
return new AnnotationTransactionAttributeSource();
}
@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionAttributeSource transactionAttributeSource() {
return new AnnotationTransactionAttributeSource();
}
@Override
public TransactionAttributeSource getTransactionAttributeSource() {
return new AnnotationTransactionAttributeSource(new DomainTransactionAnnotationParser());
}
/**
* Sets the annotationTransactionAttributeSource attribute value.
*
* @param annotationTransactionAttributeSource The annotationTransactionAttributeSource to set.
*/
public void setAnnotationTransactionAttributeSource(AnnotationTransactionAttributeSource annotationTransactionAttributeSource) {
this.annotationTransactionAttributeSource = annotationTransactionAttributeSource;
}