INT-1483 modified PollerParser not to register TX Advisor with BF, but simply inject it into PolerMetadata as value instead of reference, added tests

This commit is contained in:
Oleg Zhurakousky
2010-09-28 10:09:23 -04:00
parent 28b482c25d
commit b06fc5b15f
3 changed files with 83 additions and 4 deletions

View File

@@ -221,10 +221,8 @@ public class PollerParser extends AbstractBeanDefinitionParser {
txInterceptorBuilder.addPropertyValue("transactionAttributeSource", attributeSourceBuilder.getBeanDefinition());
BeanDefinitionBuilder txAdvisorBuilder = BeanDefinitionBuilder.genericBeanDefinition(TX_PKG_PREFIX + ".TransactionAttributeSourceAdvisor");
txAdvisorBuilder.addConstructorArgValue(txInterceptorBuilder.getBeanDefinition());
String txInterceptorName =
BeanDefinitionReaderUtils.registerWithGeneratedName(txAdvisorBuilder.getBeanDefinition(), parserContext.getRegistry());
targetBuilder.addPropertyReference("transactionAdvisor", txInterceptorName);
targetBuilder.addPropertyValue("transactionAdvisor", txAdvisorBuilder.getBeanDefinition());
}
/**

View File

@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:int="http://www.springframework.org/schema/integration"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.0.xsd">
<aop:config proxy-target-class="true" />
<int:channel id="inputChannel">
<int:queue/>
</int:channel>
<int:service-activator input-channel="inputChannel" ref="sampleService">
<int:poller max-messages-per-poll="1" fixed-rate="10000">
<int:transactional transaction-manager="txManager" />
<int:advice-chain>
<bean
class="org.springframework.integration.dispatcher.TransactionalPollerWithMixedAopConfig.SampleAdvice" />
</int:advice-chain>
</int:poller>
</int:service-activator>
<bean id="sampleService"
class="org.springframework.integration.dispatcher.TransactionalPollerWithMixedAopConfig.SampleService"/>
<bean id="foo" class="org.springframework.integration.dispatcher.TransactionalPollerWithMixedAopConfig.Foo">
<constructor-arg value="hello"/>
</bean>
<bean id="txManager"
class="org.springframework.integration.util.TestTransactionManager" />
</beans>

View File

@@ -0,0 +1,46 @@
/**
*
*/
package org.springframework.integration.dispatcher;
import static junit.framework.Assert.assertTrue;
import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.junit.Test;
import org.springframework.aop.framework.Advised;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* @author Oleg Zhurakousky
*
* This test was influenced by INT-1483 where by registering TX Advisor
* in the BeanFactory while having <aop:config> resent resulted in
* TX Advisor being applied on all beans in AC
*/
public class TransactionalPollerWithMixedAopConfig {
@Test
public void validateTransactionalProxyIsolationToThePollerOnly(){
ApplicationContext context =
new ClassPathXmlApplicationContext("TransactionalPollerWithMixedAopConfig-context.xml", this.getClass());
assertTrue(!(context.getBean("foo") instanceof Advised));
assertTrue(!(context.getBean("inputChannel") instanceof Advised));
}
public static class SampleService{
public void foo(String payload){}
}
public static class Foo{
public Foo(String value){}
}
public static class SampleAdvice implements MethodInterceptor{
public Object invoke(MethodInvocation invocation) throws Throwable {
return invocation.proceed();
}
}
}