首页 > 解决方案 > spring-data-elasticsearch 不支持@NotNull 或@NotEmpty 注释吗?

问题描述

我现在正在使用最新的 spring-data-elasticsearch ,我只是尝试使用 Spring 验证注释(如、spring-boot 2.4.5等)验证我的实体(将映射到我的弹性搜索集群上的文档中)。@NotNull@NotEmpty

但是,这些注释不起作用;即使我将 null 传递给字段(用 标记@NotNull),也没有发生错误。

这是我的 Document 实体:

@Builder
@Document(indexName = "testidx", createIndex = false)
public class Book implements Persistable<String> {
    @Id
    private final String _id;

    @NotNull
    @CreatedDate
    @Field(type = FieldType.Date, format = DateFormat.basic_date_time)
    private final Instant regTime;

    @NotNull // this annotations aren't working
    private final String bookName;

    // ...
}

我试图在官方参考资料中找到一些用例,但我找不到任何用例。spring-data-elasticsearch 不支持 Spring 验证注解吗?

谢谢!

标签: javaspring-bootspring-data-elasticsearch

解决方案


推荐阅读