您的位置:首页 > 数据库 > Mongodb

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

2017-10-05 01:25 771 查看
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字段





内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java mongodb web ssm项目
相关文章推荐