mongoDB 引起的 java.lang.StackOverflowError: null
在mongoDB保存对象的时候遇见的报错
java.lang.StackOverflowError: null
at java.base/java.util.HashMap.putVal(HashMap.java:624)
at java.base/java.util.HashMap.put(HashMap.java:607)
at org.bson.Document.put(Document.java:473)
at org.springframework.data.mongodb.util.BsonUtils.addToMap(BsonUtils.java:88)
at org.springframework.data.mongodb.core.convert.DocumentAccessor.put(DocumentAccessor.java:97)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeSimpleInternal(MappingMongoConverter.java:987)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:659)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:633)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:606)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:847)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:764)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:693)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:657)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:633)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:746)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:657)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:633)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeInternal(MappingMongoConverter.java:606)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeCollectionInternal(MappingMongoConverter.java:847)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.createCollection(MappingMongoConverter.java:764)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writePropertyInternal(MappingMongoConverter.java:693)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.writeProperties(MappingMongoConverter.java:657)
这种报错,一看就是栈溢出。我们通常会往死循环或者大量递归压栈导致栈帧堆积导致的方向排查
可是我们看到报错的信息堆栈一直是这个类
org.springframework.data.mongodb.core.convert.MappingMongoConverter
简单百度一下这个类发现
发现这个类是数据入库前,把数据结果转换成mongodb自己的文档格式的
初步确认的确是数据有问题
去翻git的提交记录发现我要报错的这个对象,昨天有同事加了一行代码
private final transient xxxService xxxService = xxxModulexxx.getInstance().getxxxxFormService();
结果发现getxxxxFormService返回的是一个bean且由@DubboReference声明消费端
//加上了@Transient这个注解
@Transient
private final transient xxxService xxxService = xxxModulexxx.getInstance().getxxxxFormService();
@Transient的作用是不参与持久化
ok,问题解决!