MongoSocketOpenException при использовании spring-boot-starter-parent 2.0.0

Я пытаюсь построить весенний загрузочный проект MongoDB, предоставленный по адресу https://spring.io/guides/gs/accessing-data-mongodb/ который использует spring-boot-starter-parent 2.0.0.RELEASE, и получаю

трассировки стека:

com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.SocketStream.open(SocketStream.java:62) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:126) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:114) ~[mongodb-driver-core-3.6.3.jar:na]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_151]

Caused by: java.net.SocketException: Socket operation on non-socket (Error setting socket option)
at java.net.PlainSocketImpl.socketSetOption0(Native Method) ~[na:1.8.0_151]
at java.net.PlainSocketImpl.socketSetOption(PlainSocketImpl.java:88) ~[na:1.8.0_151]
at java.net.AbstractPlainSocketImpl.setOption(AbstractPlainSocketImpl.java:275) ~[na:1.8.0_151]
at java.net.Socket.setTcpNoDelay(Socket.java:980) ~[na:1.8.0_151]
at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:36) ~[mongodb-driver-core-3.6.3.jar:na]
at com.mongodb.connection.SocketStream.open(SocketStream.java:57) ~[mongodb-driver-core-3.6.3.jar:na]
... 3 common frames omitted

Когда я изменил версию spring-boot-starter-parent на 1.5.9.RELEASE или 1.5.10.RELEASE, тот же код работает нормально. Так есть ли проблемы с версией 2.0.0.RELEASE при использовании данных весны Монго.

Детали системы:

версия mongod: 3.4.13

openjdk версия "1.8.0_151"

1 ответ

Мне пришлось сначала установить и запустить mongodb для spring-boot-starter-parent 2.0.x

при условии, что вы используете MacOS

# to install mongodb
➜  ~ brew install mongodb 
# To have launchd start mongodb now and restart at login
➜  ~ brew services start mongodb 

после этого все заработало как положено:

2018-04-05 22:13:43.189  INFO 26777 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2018-04-05 22:13:43.229  INFO 26777 --- [localhost:27017] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:1, serverValue:1}] to localhost:27017
2018-04-05 22:13:43.234  INFO 26777 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 3]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=3049505}
2018-04-05 22:13:43.352  INFO 26777 --- [           main] org.mongodb.driver.cluster               : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2018-04-05 22:13:43.469  INFO 26777 --- [localhost:27017] org.mongodb.driver.connection            : Opened connection [connectionId{localValue:2, serverValue:2}] to localhost:27017
2018-04-05 22:13:43.471  INFO 26777 --- [localhost:27017] org.mongodb.driver.cluster               : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 6, 3]}, minWireVersion=0, maxWireVersion=6, maxDocumentSize=16777216, logicalSessionTimeoutMinutes=30, roundTripTimeNanos=1552605}
Другие вопросы по тегам