(在开始提问之前,我的英语可能不足以清楚地描述所有内容。如果您不明白,请告诉我。)
我正在尝试通过 Kafka 将数据对象从 A spring 项目(生产者)发送到 B spring 项目(消费者)。
问题是 A 和 B 中的数据对象具有不同的类路径。所以B项目的数据类无法映射A项目的字段。
但两个对象具有相同的字段。所以我想从 A 项目获取对象作为 B 项目的参数。
错误信息
Listener failed; nested exception is
org.springframework.kafka.support.serializer.DeserializationException: failed to deserialize; nested exception is
org.springframework.messaging.converter.MessageConversionException: failed to resolve class name. Class not found [com.example.springboot.DTO.kafka.PostViewCountDTO]; nested exception is
java.lang.ClassNotFoundException: com.example.springboot.DTO.kafka.PostViewCountDTO
Run Code Online (Sandbox Code Playgroud)
构建.gradle
implementation 'org.apache.kafka:kafka-clients:2.8.0'
implementation 'org.apache.kafka:kafka_2.13:2.8.0'
implementation 'org.springframework.boot:spring-boot-starter-web:2.5.3'
Run Code Online (Sandbox Code Playgroud)
数据类(使用A和B项目)
public class PostViewCountDTO implements Serializable {
private static final long serialVersionUID = 1L;
@NotNull
private long postNo;
}
Run Code Online (Sandbox Code Playgroud)
生产者配置
@Configuration
public class PostViewProducerConfig …Run Code Online (Sandbox Code Playgroud)