Как использовать пользовательский TransactionAttributeSource с Spring 5 - PullRequest
0 голосов
/ 08 мая 2019

Весной 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.

Как я могу использовать собственный TransactionAttributeSource с Spring 5. (Работает с Spring 4.)

Есть идеи? ТИА!

1 Ответ

0 голосов
/ 08 мая 2019

Решение состоит в том, чтобы установить

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

Я нашел это здесь: Ошибка обновления Spring Boot - Неверное определение компонента с именем org.springframework.transaction.config.internalTransactionalEventListenerFactory

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...