Spring數據mongodb審核不起作用(Java配置)
實際的問題是@Id注釋。為了正確使用Spring審核,您必須定義一個ObjectId(新保存的對象為null),這就是spring決定@LastModifiedDate和@CreatedDate
之后,我找到了一種方法,可以@Id通過實現Auditable<String,String>
感謝@Felby:
我發現,僅對于@CreatedDate和@CreatedBy批注,在save()時@Id字段需要為空。無論@Id字段是否已初始化,@LastModifiedDate和@LastModifiedBy字段都起作用。
解決方法我當前正在使用Spring數據mongodb1.6.0-RELEASE,我知道它具有審核功能。我將@EnableMongoAuditing注釋放在配置類的頂部。我的豆子在下面:
@Documentpublic class MyBean{@Idprivate AnotherCustomBean anotherCustomBean = new AnotherCustomBean();@CreatedDateprivate Date creationDate;@LastModifiedDateprivate Date lastModifiedDate;...
當我用mongoTemplate.save(myBean);它保存此bean時,未設置創建日期和上次修改日期…并且沒有錯誤。
任何幫助,將不勝感激,
謝謝。
相關文章:
