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. docker-compose中volumes的問題2. 關docker hub上有些鏡像的tag被標記““This image has vulnerabilities””3. boot2docker無法啟動4. docker網絡端口映射,沒有方便點的操作方法么?5. docker安裝后出現Cannot connect to the Docker daemon.6. javascript - mock.js可以存儲數據嗎7. java - SSH框架中寫分頁時service層中不能注入分頁類8. nignx - docker內nginx 80端口被占用9. 求救一下,用新版的phpstudy,數據庫過段時間會消失是什么情況?10. mac里的docker如何命令行開啟呢?

網公網安備