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時,未設置創建日期和上次修改日期…并且沒有錯誤。
任何幫助,將不勝感激,
謝謝。
相關文章:
1. css3 - css怎么實現圖片環繞的效果2. css - 定位為absolute的父元素中的子元素 如何設置在父元素的下面?3. android - 用textview顯示html時如何寫imagegetter獲取網絡圖片4. javascript - 原生canvas中如何獲取到觸摸事件的canvas內坐標?5. JavaScript事件6. html - css布局 table cellspacing7. 在mac下出現了兩個docker環境8. javascript - jquery hide()方法無效9. 注冊賬戶文字不能左右分離10. html - vue項目中用到了elementUI問題
