无法转换类型的值[org.springframework.integration.kafka.serializer.avro

时间:2015-10-07 21:53:28

标签: spring-integration

我正在使用spring-integration-kafka组件,当尝试启动我的上下文时,我将检索以下错误:

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name '(inner bean)#1ae8bcbc': 
Unsatisfied dependency expressed through constructor argument with index 3 of type [org.apache.kafka.common.serialization.Serializer]: 
Could not convert constructor argument value of type [org.springframework.integration.kafka.serializer.avro.AvroReflectDatumBackedKafkaEncoder] 
to required type [org.apache.kafka.common.serialization.Serializer]: Failed to convert value of type 'org.springframework.integration.kafka.serializer.avro.AvroReflectDatumBackedKafkaEncoder' 
to required type 'org.apache.kafka.common.serialization.Serializer'; nested exception is java.lang.IllegalStateException: 
Cannot convert value of type [org.springframework.integration.kafka.serializer.avro.AvroReflectDatumBackedKafkaEncoder] 
to required type [org.apache.kafka.common.serialization.Serializer]: no matching editors or conversion strategy found

我的bean定义是:

int-kafka:producer-context id="kafkaProducerContext" producer-properties="producerProperties">
    <int-kafka:producer-configurations>
        <int-kafka:producer-configuration broker-list="localhost:9092"
                key-class-type="java.lang.String"
                value-class-type="org.springframework.integration.samples.kafka.user.User"
                topic="test1"
                value-serializer="kafkaSpecificEncoder"
                key-serializer="kafkaReflectionEncoder"
                partitioner="customPartitioner"/>

其中kafkaSpecificEncoder的声明如下:

<bean id="kafkaSpecificEncoder" class="org.springframework.integration.kafka.serializer.avro.AvroSpecificDatumBackedKafkaEncoder">
    <constructor-arg value="org.springframework.integration.samples.kafka.user.User" />
</bean>

用户obj是从avro自动生成的。 基本上我试图运行一个旧的例子,但我不明白我错在哪里

感谢您的帮助

1 个答案:

答案 0 :(得分:1)

您有迁移错误。

请参阅:您使用Encoder,但请将其指定为真正需要value-serializer实施的org.apache.kafka.common.serialization.Serializer

所以,或者使用key(value)-encoder进行<int-kafka:producer-configuration>配置,或者使用EncoderAdaptingSerializer包装您的编码器。