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. javascript - 使用form進行頁面跳轉,但是很慢,如何加一個Loading?2. python 計算兩個時間相差的分鐘數,超過一天時計算不對3. angular.js - angularjs 注入模塊報錯 很怪異... 求解惑4. javascript - ES6規范下 repeat 函數報錯 Invalid count value5. docker-machine添加一個已有的docker主機問題6. javascript - 后臺管理系統左側折疊導航欄數據較多,怎么樣直接通過搜索去定位到具體某一個菜單項位置,并展開當前菜單7. docker-compose中volumes的問題8. javascript - JS 里面的 delete object.key 到底刪除了什么?9. javascript - html5的data屬性怎么指定一個function函數呢?10. angular.js - 輸入郵箱地址之后, 如何使其自動在末尾添加分號?
