spring-boot - 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.
解决方案
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.
推荐阅读
- java - 如何在 Selenium Java 中使用键盘键复制段落
- c# - ASP.NET Core 依赖注入 - 如何创建实例?
- google-drive-api - 使用服务帐户将文件上传到共享的 Google Drive 文件夹时,为什么会收到空的 200 OK 响应?
- c - 返回结构数组时遇到问题
- python - 如何使用代码在 Python 中制作永久文件?- Repl.it
- android - Windows 和 Android 应用程序是否需要 SSL?
- c - 使用指针对c中的字符串数组进行排序
- flutter - 当应用程序完全关闭时发送颤动的 Firebase 云消息
- unity3d - 从 Atan2 到四元数的对象没有以正确的方向旋转
- r - 如何更改ar数据表的结构