com.mongodb.MongoSocketOpenException: Exception opening socket

在类SpringbootdemoApplication上右键Run as选择Spring Boot App后Console输出报错日志如下:

com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:63) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:113) ~[mongodb-driver-core-3.4.2.jar:na]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_91]
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_91]
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) ~[na:1.8.0_91]
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) ~[na:1.8.0_91]
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) ~[na:1.8.0_91]
at java.net.AbstractPlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_91]
at java.net.PlainSocketImpl.connect(Unknown Source) ~[na:1.8.0_91]
at java.net.SocksSocketImpl.connect(Unknown Source) ~[na:1.8.0_91]
at java.net.Socket.connect(Unknown Source) ~[na:1.8.0_91]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:57) ~[mongodb-driver-core-3.4.2.jar:na]
at com.mongodb.connection.SocketStream.open(SocketStream.java:58) ~[mongodb-driver-core-3.4.2.jar:na]
... 3 common frames omitted 

第一种可能:来自上网百度,找到一篇文章说原因是springboot自动配置了支持mongodb。在启动springboot时会自动实例化一个mongo实例,需要禁用自动配置 ,增加 @SpringBootApplication(exclude = MongoAutoConfiguration.class)

下面是例子:

com.mongodb.MongoSocketOpenException: Exception opening socket_第1张图片

原文章:https://blog.csdn.net/xuyw10000/article/details/72918360

             https://www.cnblogs.com/pengweild/p/7468404.html


第二种可能:项目配置的时候,产生了问题
使用了MongoDB,但是没有做相应的配置

com.mongodb.MongoSocketOpenException: Exception opening socket_第2张图片

你可能感兴趣的:(java)