javaxの検証んではない検証notNullを

サンドロ・レイ:

私はCouchbaseのための春のデータを使用していますspringBoot 2.1.9.RELEASEアプリケーションを持っています

私は、このオブジェクトを持っています

@Data
@AllArgsConstructor
@NoArgsConstructor
public class Hostel<T> {

    @NotNull
    @JsonProperty("_location")
    private T location;

}

この他の1

@Document
@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(of = { "id" })
@Builder
public class HTMDoc {

    @Id
    private String id;
    @NotNull
    @Field
    private Hostel hostel;

}

サービスの

public HTMDoc create(@Valid HTMDoc doc) {
    return repository.save(doc);
}

テストで

service.create(new HTMDoc());

私は保存するとき、私はこのエラーを得た代わりのホステルフィールドで検証NOTNULL

 org.springframework.data.mapping.MappingException: An ID property is needed, but not found/could not be generated on this entity.
ジョージ:

あなたは使用する必要があります@org.springframework.validation.annotation.Validated検証を可能にするために、あなたのサービスクラスの上に注釈を。

@Validated
@Service
public class DocService {
  public HTMDoc create(@Valid HTMDoc doc) {
    return repository.save(doc);
  }
}

おすすめ

転載: http://43.154.161.224:23101/article/api/json?id=331219&siteId=1