Spring數(shù)據(jù)mongodb審核不起作用(Java配置)
實際的問題是@Id注釋。為了正確使用Spring審核,您必須定義一個ObjectId(新保存的對象為null),這就是spring決定@LastModifiedDate和@CreatedDate
之后,我找到了一種方法,可以@Id通過實現(xiàn)Auditable<String,String>
感謝@Felby:
我發(fā)現(xiàn),僅對于@CreatedDate和@CreatedBy批注,在save()時@Id字段需要為空。無論@Id字段是否已初始化,@LastModifiedDate和@LastModifiedBy字段都起作用。
解決方法我當(dāng)前正在使用Spring數(shù)據(jù)mongodb1.6.0-RELEASE,我知道它具有審核功能。我將@EnableMongoAuditing注釋放在配置類的頂部。我的豆子在下面:
@Documentpublic class MyBean{@Idprivate AnotherCustomBean anotherCustomBean = new AnotherCustomBean();@CreatedDateprivate Date creationDate;@LastModifiedDateprivate Date lastModifiedDate;...
當(dāng)我用mongoTemplate.save(myBean);它保存此bean時,未設(shè)置創(chuàng)建日期和上次修改日期…并且沒有錯誤。
任何幫助,將不勝感激,
謝謝。
相關(guān)文章:
1. docker-machine添加一個已有的docker主機問題2. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?3. 關(guān)docker hub上有些鏡像的tag被標記““This image has vulnerabilities””4. css - 求推薦適用于vue2的框架 像bootstrap這種類型的5. Span標簽6. SessionNotFoundException:會話ID為null。調(diào)用quit()后使用WebDriver嗎?(硒)7. angular.js使用$resource服務(wù)把數(shù)據(jù)存入mongodb的問題。8. css - 關(guān)于div自適應(yīng)問題,大家看圖吧,說不清9. redis啟動有問題?10. java - Collections類里的swap函數(shù),源碼為什么要新定義一個final的List型變量l指向傳入的list?
