-
Notifications
You must be signed in to change notification settings - Fork 784
Closed
Description
Problem description
This problem was noted after a migration from Spring Boot 2.4.1 (which was working fine) to Spring Boot 2.6.0.
When using a Kafka transaction manager together with Sleuth, the following error occurs:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name
'org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration': Bean instantiation via constructor failed; nested
exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate
[org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration]: Constructor threw exception; nested exception is
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'kafkaTransactionManager' is expected to be of
type 'org.springframework.kafka.transaction.KafkaAwareTransactionManager' but was actually of type
'org.springframework.cloud.sleuth.instrument.tx.TracePlatformTransactionManager'
...
Caused by: org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'kafkaTransactionManager' is expected to be of type 'org.springframework.kafka.transaction.KafkaAwareTransactionManager' but was actually of type 'org.springframework.cloud.sleuth.instrument.tx.TracePlatformTransactionManager'
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1390)
at org.springframework.beans.factory.support.DefaultListableBeanFactory$DependencyObjectProvider.getIfUnique(DefaultListableBeanFactory.java:2063)
at org.springframework.boot.autoconfigure.kafka.KafkaAnnotationDrivenConfiguration.<init>(KafkaAnnotationDrivenConfiguration.java:94)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:211)
... 21 common frames omitted
Reproduction
In order to reproduce the problem, please use this sample and have a local Kafka instance running on the default port.
Analysis
- The
TracePlatformTransactionManagerBeanPostProcessor
wraps the beankafkaTransactionManager
of typeKafkaTransactionManager
in aTracePlatformTransactionManager
. - The
KafkaTransactionManager
is created inKafkaAutoConfiguration
ifspring.kafka.producer.transaction-id-prefix
is set and a typeKafkaAwareTransactionManager
is expected (and enforced) for this bean.