【问题标题】:How to use a custom 'TransactionAttributeSource' with Spring 5如何在 Spring 5 中使用自定义的“TransactionAttributeSource”
【发布时间】:2019-05-08 10:42:35
【问题描述】:

在 Spring 5 中有 ProxyTransactionManagementConfiguration

这定义了:

@Bean
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
public TransactionAttributeSource transactionAttributeSource() {
    return new AnnotationTransactionAttributeSource();
}

当我在自己的配置中定义自己的TransactionAttributeSource 时:

@Bean
@Primary
public TransactionAttributeSource transactionAttributeSource() {
    return new RollbackOnAllTransactionAttributeSource();
}

我得到了错误:

org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'transactionAttributeSource' defined in class path resource [...]: Cannot register bean definition [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=true; factoryBeanName=[...]; factoryMethodName=transactionAttributeSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [...]] for bean 'transactionAttributeSource': There is already [Root bean: class [null]; scope=; abstract=false; lazyInit=false; autowireMode=3; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration; factoryMethodName=transactionAttributeSource; initMethodName=null; destroyMethodName=(inferred); defined in class path resource [org/springframework/transaction/annotation/ProxyTransactionManagementConfiguration.class]] bound.

如何在 Spring 5 中使用自定义的“TransactionAttributeSource”。 (它适用于 Spring 4。)

有什么想法吗?蒂亚!

【问题讨论】:

    标签: java spring transactions spring-transactions


    【解决方案1】:

    解决办法是设置

    spring.main.allow-bean-definition-overriding=true
    

    我在这里找到它:Spring Boot Upgrade Error - Invalid bean definition with name org.springframework.transaction.config.internalTransactionalEventListenerFactory

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-12-15
      • 1970-01-01
      • 1970-01-01
      • 2022-07-13
      • 1970-01-01
      • 2018-07-09
      • 1970-01-01
      相关资源
      最近更新 更多