开发者社区> 问答> 正文

spring mongdb 时不时会报错?报错

org.springframework.data.mongodb.UncategorizedMongoDbException: Exception receiving message; nested exception is com.mongodb.MongoSocketReadException: Exception receiving message
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:107)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2114)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:464)
at org.springframework.data.mongodb.core.MongoTemplate.saveDBObject(MongoTemplate.java:1080)
at org.springframework.data.mongodb.core.MongoTemplate.doSave(MongoTemplate.java:1015)
at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:961)
at org.springframework.data.mongodb.core.MongoTemplate.save(MongoTemplate.java:949)
at com.foundation.mongo.dao.impl.MongoBaseDaoImpl.save(MongoBaseDaoImpl.java:108)
at com.foundation.service.record.service.impl.BaseRecordServiceImpl.saveRecord(BaseRecordServiceImpl.java:33)
at com.foundation.service.record.service.impl.IndicatorRecordService.saveIndicator(IndicatorRecordService.java:47)
at com.foundation.service.record.service.impl.IndicatorRecordService.saveIndicators(IndicatorRecordService.java:119)
at com.foundation.service.record.service.impl.IndicatorRecordService$$FastClassBySpringCGLIB$$56955274.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.foundation.service.record.service.impl.IndicatorRecordService$$EnhancerBySpringCGLIB$$d2c761dd.saveIndicators(<generated>)
at com.foundation.service.canal.listener.BusiSyncHandle.syncBusiExamValue(BusiSyncHandle.java:741)
at com.foundation.service.canal.listener.BusiSyncHandle$$FastClassBySpringCGLIB$$57f9d56c.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:720)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:655)
at com.foundation.service.canal.listener.BusiSyncHandle$$EnhancerBySpringCGLIB$$cf8285c5.syncBusiExamValue(<generated>)
at com.foundation.service.canal.listener.BusiAnscWatcherThread.gotoSyncData(BusiAnscWatcherThread.java:232)
at com.foundation.service.canal.listener.BusiAnscWatcherThread.dealBusinessData(BusiAnscWatcherThread.java:181)
at com.foundation.service.canal.listener.BusiAnscWatcherThread.switchHandle(BusiAnscWatcherThread.java:149)
at com.foundation.service.canal.listener.BusiAnscWatcherThread.init(BusiAnscWatcherThread.java:89)
at com.foundation.service.canal.listener.BusiAnscWatcherThread.run(BusiAnscWatcherThread.java:53)
Caused by: com.mongodb.MongoSocketReadException: Exception receiving message
at com.mongodb.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:481)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:226)
at com.mongodb.connection.UsageTrackingInternalConnection.receiveMessage(UsageTrackingInternalConnection.java:105)
at com.mongodb.connection.DefaultConnectionPool$PooledConnection.receiveMessage(DefaultConnectionPool.java:438)
at com.mongodb.connection.WriteCommandProtocol.receiveMessage(WriteCommandProtocol.java:262)
at com.mongodb.connection.WriteCommandProtocol.execute(WriteCommandProtocol.java:104)
at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:67)
at com.mongodb.connection.InsertCommandProtocol.execute(InsertCommandProtocol.java:37)
at com.mongodb.connection.DefaultServer$DefaultServerProtocolExecutor.execute(DefaultServer.java:168)
at com.mongodb.connection.DefaultServerConnection.executeProtocol(DefaultServerConnection.java:289)
at com.mongodb.connection.DefaultServerConnection.insertCommand(DefaultServerConnection.java:118)
at com.mongodb.operation.InsertOperation.executeCommandProtocol(InsertOperation.java:76)
at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:142)
at com.mongodb.operation.BaseWriteOperation$1.call(BaseWriteOperation.java:134)
at com.mongodb.operation.OperationHelper.withConnectionSource(OperationHelper.java:232)
at com.mongodb.operation.OperationHelper.withConnection(OperationHelper.java:223)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:134)
at com.mongodb.operation.BaseWriteOperation.execute(BaseWriteOperation.java:61)
at com.mongodb.Mongo.execute(Mongo.java:827)
at com.mongodb.Mongo$2.execute(Mongo.java:810)
at com.mongodb.DBCollection.executeWriteOperation(DBCollection.java:333)
at com.mongodb.DBCollection.insert(DBCollection.java:328)
at com.mongodb.DBCollection.insert(DBCollection.java:319)
at com.mongodb.DBCollection.insert(DBCollection.java:289)
at com.mongodb.DBCollection.insert(DBCollection.java:255)
at com.mongodb.DBCollection.insert(DBCollection.java:177)
at com.mongodb.DBCollection.save(DBCollection.java:398)
at com.mongodb.DBCollection.save(DBCollection.java:373)
at org.springframework.data.mongodb.core.MongoTemplate$11.doInCollection(MongoTemplate.java:1085)
at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:462)
... 38 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketInputStream.read(SocketInputStream.java:196)
at java.net.SocketInputStream.read(SocketInputStream.java:122)
at com.mongodb.connection.SocketStream.read(SocketStream.java:85)
at com.mongodb.connection.InternalStreamConnection.receiveResponseBuffers(InternalStreamConnection.java:492)
at com.mongodb.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:222)
... 66 more





配置信息如下:

<!-- 开启注解 -->
    <context:property-placeholder location="classpath:mongodb.properties" ignore-unresolvable="true"/>

    <mongo:mongo-client host="${mongo.host}" port="${mongo.port}" id="mongo">
    </mongo:mongo-client>

    <mongo:db-factory id="mongoDbFactory" dbname="${mongo.dbname}" mongo-ref="mongo" />





展开
收起
爱吃鱼的程序员 2020-06-08 20:08:17 807 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    有可能是程序获取到了已关闭的连接,比如线程池一个连接长时间未使用,导致断开,这时获取到这个连接再使用的时候就会报这个错误,

    <spanstyle="color:#e8bf6a;"><<spanstyle="color:#9876aa;">mongo<spanstyle="color:#e8bf6a;">:client-options<spanstyle="color:#e8bf6a;"><spanstyle="color:#bababa;">connections-per-host<spanstyle="color:#a5c261;">="500"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">threads-allowed-to-block-for-connection-multiplier<spanstyle="color:#a5c261;">="50"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">connect-timeout<spanstyle="color:#a5c261;">="10000"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">max-wait-time<spanstyle="color:#a5c261;">="25000"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">socket-keep-alive<spanstyle="color:#a5c261;">="true"<spanstyle="color:#a5c261;"><spanstyle="color:#bababa;">socket-timeout<spanstyle="color:#a5c261;">="0"<spanstyle="color:#e8bf6a;">/>

    我设置了一下参数,这个问题到目前为之,就没有再出现过了。后续再跟踪一下。应该是设置的

    <spanstyle="color:#BABABA;">socket-timeout<spanstyle="color:#A5C261;">="0"
    起了作用

    2020-06-08 20:08:33
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
云栖社区特邀专家徐雷Java Spring Boot开发实战系列课程(第20讲):经典面试题与阿里等名企内部招聘求职面试技巧 立即下载
微服务架构模式与原理Spring Cloud开发实战 立即下载
阿里特邀专家徐雷Java Spring Boot开发实战系列课程(第18讲):制作Java Docker镜像与推送到DockerHub和阿里云Docker仓库 立即下载