首页 > 解决方案 > JSON deserializer conflict with Spring Boot Starter Web and Spring Cloud Stream

问题描述

I have a fairly simple Java app that listens to a Kafka topic for JSON messages.

These are the main dependencies and versions:

id 'org.springframework.boot' version '2.3.5.RELEASE'
...
set('springCloudVersion', "Hoxton.SR9")
...
implementation 'org.springframework.cloud:spring-cloud-stream'
implementation 'org.springframework.cloud:spring-cloud-stream-binder-kafka'

The application.properties config that specifies the JSON format:

spring.cloud.stream.bindings.listener-in-0.content-type = application/json

And the "core loop":

@Bean
public Consumer<Message<MyDataModel>> listener() {
    return message -> {
        ...

And it works like a charm. But now I'm trying to add a /metrics endpoint to the app, with the Actuator library:

implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-actuator'

After adding these to build.gradle, without changing anything in the code itself, the consumer in the above snippet fails to deserialize the incoming messages, every field of the model object is null.

Clearly, the spring-boot-starter-web package overwrites the JSON handling mechanism that came with the spring-cloud-stream library, but I have no idea what to do. Experimented with excluding parts of the web-starter library and changing around the springBoot version, but no success yet.

标签: spring-bootgradlejacksonspring-cloud-streamspring-boot-actuator

解决方案


Upgrading the springboot version to 2.4.2 from 2.3.5.RELEASE, and spring-cloud version to 2020.0.1 from Hoxton.SR9 solved the issue for us.


推荐阅读