spring-data mongo@createdat注解不使用嵌套文档字段

r1zhe5dt  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(413)

我正在使用SpringBoot2.4.0和SpringDataMongo。
Map到集合的pojo类是:

@SuppressFBWarnings(value = {"EI_EXPOSE_REP", "EI_EXPOSE_REP2"},
  justification = "This is a bean")
@Document(collection = "Posts")
@Data
@Builder
public class Post {

@Id
private String id;
private ActorInfo actorInfo;
private String text;
private Media media;
private int likes; 
private Meta meta;
@Version
private Integer version;

@Data
@Builder
public static class Meta {
   @CreatedDate // <-- this is not working
   private Instant createdAt;
   @LastModifiedDate // <-- this is not working
   private Instant updatedAt;
   private String event; 
}

}
我正在使用mongorepository使用save()将上面的pojo保存到db中。但是我没有看到createdat和updatedat在集合中被填充。
以下是保存在集合中的内容:

{ "_id" : ObjectId("600fc6b23d5ebf145b7bbc0d"), "actorInfo" : { "_id" : "1", "role" : "USER" }, "text" : "Helo", "likes" : 0, "meta" : { "event" : "CREATED" }, "version" : 0, "_class" : "com.highstreet.socialmediaservice.adpater.output.type.Post" }
ncgqoxb0

ncgqoxb01#

你启用审计了吗?https://docs.spring.io/spring-data/mongodb/docs/current/reference/html/#mongo.auditing

相关问题