@Transactional qualifiers match against transaction manager definitions in parent contexts as well (SPR-7679)
This commit is contained in:
parent
d4123d0637
commit
0f75cebdff
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -21,6 +21,7 @@ import java.util.Map;
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory;
|
import org.springframework.beans.factory.BeanFactory;
|
||||||
import org.springframework.beans.factory.BeanFactoryUtils;
|
import org.springframework.beans.factory.BeanFactoryUtils;
|
||||||
|
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||||
import org.springframework.beans.factory.annotation.Qualifier;
|
import org.springframework.beans.factory.annotation.Qualifier;
|
||||||
import org.springframework.beans.factory.config.BeanDefinition;
|
import org.springframework.beans.factory.config.BeanDefinition;
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||||
|
|
@ -103,7 +104,8 @@ public abstract class TransactionAspectUtils {
|
||||||
* value (through <qualifier<> or @Qualifier)
|
* value (through <qualifier<> or @Qualifier)
|
||||||
*/
|
*/
|
||||||
private static boolean isQualifierMatch(String qualifier, String beanName, ConfigurableListableBeanFactory bf) {
|
private static boolean isQualifierMatch(String qualifier, String beanName, ConfigurableListableBeanFactory bf) {
|
||||||
if (bf.containsBeanDefinition(beanName)) {
|
if (bf.containsBean(beanName)) {
|
||||||
|
try {
|
||||||
BeanDefinition bd = bf.getMergedBeanDefinition(beanName);
|
BeanDefinition bd = bf.getMergedBeanDefinition(beanName);
|
||||||
if (bd instanceof AbstractBeanDefinition) {
|
if (bd instanceof AbstractBeanDefinition) {
|
||||||
AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
|
AbstractBeanDefinition abd = (AbstractBeanDefinition) bd;
|
||||||
|
|
@ -123,6 +125,10 @@ public abstract class TransactionAspectUtils {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
|
// ignore - can't compare qualifiers for a manually registered singleton object
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright 2002-2010 the original author or authors.
|
* Copyright 2002-2011 the original author or authors.
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
|
|
@ -23,6 +23,8 @@ import org.aopalliance.intercept.MethodInterceptor;
|
||||||
import org.aopalliance.intercept.MethodInvocation;
|
import org.aopalliance.intercept.MethodInvocation;
|
||||||
|
|
||||||
import org.springframework.aop.support.AopUtils;
|
import org.springframework.aop.support.AopUtils;
|
||||||
|
import org.springframework.context.ApplicationContext;
|
||||||
|
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||||
import org.springframework.transaction.CallCountingTransactionManager;
|
import org.springframework.transaction.CallCountingTransactionManager;
|
||||||
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
import org.springframework.transaction.support.TransactionSynchronizationManager;
|
||||||
|
|
@ -36,26 +38,18 @@ public class AnnotationDrivenTests extends TestCase {
|
||||||
|
|
||||||
public void testWithProxyTargetClass() throws Exception {
|
public void testWithProxyTargetClass() throws Exception {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass());
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenProxyTargetClassTests.xml", getClass());
|
||||||
CallCountingTransactionManager tm1 = context.getBean("transactionManager1", CallCountingTransactionManager.class);
|
doTestWithMultipleTransactionManagers(context);
|
||||||
CallCountingTransactionManager tm2 = context.getBean("transactionManager2", CallCountingTransactionManager.class);
|
|
||||||
TransactionalService service = context.getBean("service", TransactionalService.class);
|
|
||||||
assertTrue(AopUtils.isCglibProxy(service));
|
|
||||||
service.setSomething("someName");
|
|
||||||
assertEquals(1, tm1.commits);
|
|
||||||
assertEquals(0, tm2.commits);
|
|
||||||
service.doSomething();
|
|
||||||
assertEquals(1, tm1.commits);
|
|
||||||
assertEquals(1, tm2.commits);
|
|
||||||
service.setSomething("someName");
|
|
||||||
assertEquals(2, tm1.commits);
|
|
||||||
assertEquals(1, tm2.commits);
|
|
||||||
service.doSomething();
|
|
||||||
assertEquals(2, tm1.commits);
|
|
||||||
assertEquals(2, tm2.commits);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testWithConfigurationClass() throws Exception {
|
public void testWithConfigurationClass() throws Exception {
|
||||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("annotationDrivenConfigurationClassTests.xml", getClass());
|
AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
|
||||||
|
parent.register(TransactionManagerConfiguration.class);
|
||||||
|
parent.refresh();
|
||||||
|
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"annotationDrivenConfigurationClassTests.xml"}, getClass(), parent);
|
||||||
|
doTestWithMultipleTransactionManagers(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doTestWithMultipleTransactionManagers(ApplicationContext context) {
|
||||||
CallCountingTransactionManager tm1 = context.getBean("transactionManager1", CallCountingTransactionManager.class);
|
CallCountingTransactionManager tm1 = context.getBean("transactionManager1", CallCountingTransactionManager.class);
|
||||||
CallCountingTransactionManager tm2 = context.getBean("transactionManager2", CallCountingTransactionManager.class);
|
CallCountingTransactionManager tm2 = context.getBean("transactionManager2", CallCountingTransactionManager.class);
|
||||||
TransactionalService service = context.getBean("service", TransactionalService.class);
|
TransactionalService service = context.getBean("service", TransactionalService.class);
|
||||||
|
|
|
||||||
|
|
@ -18,8 +18,6 @@
|
||||||
|
|
||||||
<bean id="txCheckingInterceptor" class="org.springframework.transaction.config.AnnotationDrivenTests$TransactionCheckingInterceptor"/>
|
<bean id="txCheckingInterceptor" class="org.springframework.transaction.config.AnnotationDrivenTests$TransactionCheckingInterceptor"/>
|
||||||
|
|
||||||
<bean id="transactionManagerConfig" class="org.springframework.transaction.config.TransactionManagerConfiguration"/>
|
|
||||||
|
|
||||||
<bean id="service" class="org.springframework.transaction.config.TransactionalService"/>
|
<bean id="service" class="org.springframework.transaction.config.TransactionalService"/>
|
||||||
|
|
||||||
</beans>
|
</beans>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue