[英]Why does the Java App lose connection after MongoDB restarted?
The MongoDB is in a replica set with three members. MongoDB位于具有三个成员的副本集中。 Sometimes one or two MongoDB instances restarted, the Java Apps lose connection and show the following error and then I have to restart the Java Apps manually so as to re-connect the MongoDB replica set: 有时一个或两个MongoDB实例重新启动,Java Apps失去连接并显示以下错误,然后我必须手动重新启动Java Apps才能重新连接MongoDB副本集:
org.springframework.dao.DataAccessResourceFailureException:
Unable to connect to any server that matches
{serverSelectors=[ReadPreferenceServerSelector{readPreference=secondaryPreferred},
LatencyMinimizingServerSelector{acceptableLatencyDifference=15 ms}]};
nested exception is com.mongodb.MongoServerSelectionException:
Unable to connect to any server that matches
{serverSelectors=[ReadPreferenceServerSelector{readPreference=secondaryPreferred},
LatencyMinimizingServerSelector{acceptableLatencyDifference=15 ms}]}
I would like to know are there any solutions to keep the connectivity even if the MongoDB instances restarted? 我想知道有什么解决方案即使重启MongoDB实例也能保持连接性吗? Thank you so much. 非常感谢。
Thank you so much. 非常感谢。 I fixed the problem by changing the configuration of spring data. 我通过更改spring数据的配置解决了该问题。 I set socket-timeout="1500" before. 我之前设置了socket-timeout =“ 1500”。 I should not set socket timeout. 我不应该设置套接字超时。 Defaults to 0 (infinite time). 默认为0(无限时间)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.