(在开始提问之前,我的英语可能不足以清楚地描述所有内容。如果您不明白,请告诉我。)
我正在尝试通过 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) 这可能是一个愚蠢的问题。
当我Optional.isEmpty()在代码中使用如下所示时
Optional<List<String>> optional = Optional.of(new ArrayList<>());
optional.isEmpty(); // only checks if the value is NULL or not.
Run Code Online (Sandbox Code Playgroud)
isEmpty()方法只是检查值null是否存在。
public boolean isEmpty() {
return value == null;
}
Run Code Online (Sandbox Code Playgroud)
这个方法名称对我来说似乎不太清楚。
我想知道为什么这个方法被命名isEmpty(),而不是isNull()因为它在幕后执行空检查?