Fix APC registration for @EnableTransactionManagement
Prior to this change, @EnableTransactionManagement (via the ProxyTransactionManagementConfiguration class) did not properly register its auto-proxy creator through the usual AopConfigUtils methods. It was trying to register the APC as a normal @Bean method, but this causes issues (SPR-8494) with the logic in AopConfigUtils#registerOrEscalateApcAsRequired, which expects the APC bean definition to have a beanClassName property. When the APC is registered via a @Bean definition, it is actually a factoryBean/factoryMethod situation with no directly resolvable beanClass/beanClassName. Rather than trying to rework how AopConfigUtils works, a @PostConstruct method has been added to ProxyTransactionManagementConfiguration to call the usual AopConfigUtils registration methods. Issue: SPR-8411, SPR-8494
This commit is contained in:
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.springframework.transaction.annotation;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import org.springframework.aop.config.AopConfigUtils;
|
||||
import org.springframework.aop.framework.autoproxy.InfrastructureAdvisorAutoProxyCreator;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Role;
|
||||
@@ -39,6 +42,17 @@ import org.springframework.transaction.interceptor.TransactionInterceptor;
|
||||
@Configuration
|
||||
public class ProxyTransactionManagementConfiguration extends AbstractTransactionManagementConfiguration {
|
||||
|
||||
@Autowired
|
||||
private DefaultListableBeanFactory registry;
|
||||
|
||||
@PostConstruct
|
||||
public void registerAutoProxyCreator() {
|
||||
AopConfigUtils.registerAutoProxyCreatorIfNecessary(registry);
|
||||
if ((Boolean)enableTx.get("proxyTargetClass")) {
|
||||
AopConfigUtils.forceAutoProxyCreatorToUseClassProxying(registry);
|
||||
}
|
||||
}
|
||||
|
||||
@Bean(name=TransactionManagementConfigUtils.TRANSACTION_ADVISOR_BEAN_NAME)
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public BeanFactoryTransactionAttributeSourceAdvisor transactionAdvisor() {
|
||||
@@ -67,12 +81,4 @@ public class ProxyTransactionManagementConfiguration extends AbstractTransaction
|
||||
return interceptor;
|
||||
}
|
||||
|
||||
// TODO: deal with escalation of APCs
|
||||
@Bean(name=AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME)
|
||||
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
|
||||
public InfrastructureAdvisorAutoProxyCreator apc() {
|
||||
InfrastructureAdvisorAutoProxyCreator apc = new InfrastructureAdvisorAutoProxyCreator();
|
||||
apc.setProxyTargetClass((Boolean) this.enableTx.get("proxyTargetClass"));
|
||||
return apc;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user