web项目整合MongoDb出现No converter found capable of converting from org.bson.types.ObjectId to type Long异常

Spring、SpringMVC、MyBatis框架整合 MongoDb ,启动web项目时出现异常,项目不能运行,查看原因是出现如下异常: 

with root cause org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.bson.types.ObjectId to type java.lang.Long

异常堆栈如下:

org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [springMvcDispatcherServlet] in context with path [/conference] threw exception [Request processing failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.bson.types.ObjectId to type java.lang.Long] with root cause 
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.bson.types.ObjectId to type java.lang.Long
解决方法:

Spring使用MongoDb帮助文档

在MongoDb里要求每个文档都需要有_id 字段,java类中有如下情况会被映射为_id字段

如果1个字段加上了 @Id (org.springframework.data.annotation.Id)注解,那么将bean保存到数据库时就会把该字段映射为文档中的_id字段
如果java对象中没有 @Id 注解,名字为id 的字段将会被映射为文档中的_id字段

 

mongo不止查询时会entity和mongo库中数据映射,插入也会映射项目中insert   list时entity的id为null报错,mongo中存入entity,即属性为_class字段为 com.tk.mer.entity.MerSku

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值