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
字段
web项目整合MongoDb出现No converter found capable of converting from org.bson.types.ObjectId to type Long异常
SSM框架整合 MongoDb ,启动项目时出现异常,出现如下异常:with root cause org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type org.bson.types.ObjectId to Long
一、写在前面
人人都想成为全栈码农,作为一个
web
前端开发人员,通往全栈的简洁之路,貌似就是node.js了。前段时间学习了node.js,来谈谈新手如何快速的搭建自己的
web
服务,开启全栈之路。
二、安装node.js
接触过后端开发的人都知道,首先要安装服务。作为新手,肯定是选择最简单的可视化安装了(傻瓜式下一步,其它的方式等熟悉相关操作后自然就会了的),通过官网http://nodejs.
org
/dist/v0.6.1/node-v0.6.1.msi 下载电脑适配的安装包(这个是windows的,买不起mac啊),然后根据引导安装就可以了,默认安装在C:\Program File
解决错误: No
converter
found
ca
pable
of
convert
ing
from
type
[
java
.lang.Str
ing
] to
type
[
java
.lang.Class
<dependency>
<group
Id
>com.alibaba</group
Id
>
<artifact
Id
>dru
id
-spr
ing
-boot-starter</artifact
Id
>
<version>...
Traceback (most recent
ca
ll last):
File /home/cisco/spark-mongo-test.py, line 7, in
df = spark.read.format(com.
mongodb
.spark.sql.DefaultSource).load()
File /home/cisco/spark-2.2.0-bin-hadoop2.7/python/lib/pyspark.zip/pyspark/sql/readwriter.py, line 165, in load
Object
Id
,在mongo中,存储的文档必须有一个"_
id
"键。这个键的值可以是任何类型的,默认是个
Object
Id
对象。
之前在把
Object
Id
类型的json格式转化成
Object
Id
时候报错。用的是fastjson工具,下面是main方法模拟的报错代码:
public static vo
id
main(Str
ing
[] args) {
Object
Id
id
=
Object
Id
.get();
JSON
Object
json
Object
= (JSON
Object
)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java
:39)
sun.reflect.Delegat
ing
MethodAccessorImpl.invoke(Delegat