[JAVA-2292] Integrated with Spring Boot - automatic connection localhost:27017 Created: 30/Aug/16  Updated: 11/Sep/19  Resolved: 30/Aug/16

Status: Closed
Project: Java Driver
Component/s: Connection Management, Internal
Affects Version/s: 3.3.0
Fix Version/s: None

Type: Task Priority: Critical - P2
Reporter: shengyao Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Spring Boot



 Description   

It will automatic recursive connect to localhost:27017
Just add the jar to environment. (no any code)

Here is the stack

2016-08-30 17:22:50 [cluster-ClusterId{value='57c5502ab2a8e01738289ab0', description='null'}-localhost:27017] INFO  org.mongodb.driver.cluster -Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
	at com.mongodb.connection.SocketStream.open(SocketStream.java:63)
	at com.mongodb.connection.InternalStreamConnection.open(InternalStreamConnection.java:115)
	at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:116)
	at java.lang.Thread.run(Unknown Source)
Caused by: java.net.ConnectException: Connection refused: connect
	at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
	at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
	at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
	at java.net.PlainSocketImpl.connect(Unknown Source)
	at java.net.SocksSocketImpl.connect(Unknown Source)
	at java.net.Socket.connect(Unknown Source)
	at com.mongodb.connection.SocketStreamHelper.initialize(SocketStreamHelper.java:50)
	at com.mongodb.connection.SocketStream.open(SocketStream.java:58)



 Comments   
Comment by shengyao [ 31/Aug/16 ]

Hi Ross
Thank you very much for your help !
1> The project is based on SpringBoot , but I am using the jar [mongodb-driver-3.3.0] instead of [spring-data-mongodb-1.9.2.RELEASE].
so i guess the issue is the incompatibility on SpringBoot and MONGODB JAVA DRIVER

2> I notice the Server Discover cause this issue, I am trying to add the code in DefaultServerMonitor.java line 115
if("localhost".equals(serverId.getAddress().getHost()) || "127.0.0.1".equals(serverId.getAddress().getHost()))

{ Thread.sleep(Long.MAX_VALUE); }

I know it is not a good way to prevent the issue. If there is any configuration place I missed, please let me know.

Thanks again~

shengyao

Comment by Ross Lawley [ 30/Aug/16 ]

Hi shengyao15,

Thanks for the ticket, it looks like you haven't configured the MongoDB instance in Spring and the default setting for the Mongo connection is to use localhost and port 27107. Please see the Spring Data MongoDB documentation for more information about configuring Spring Data, specifically the connecting to MongoDB with Spring.

Regarding, seeing multiple connection attempts, this is working as expected as the underlying driver follows the Server Discover and Monitoring Specification.

Just to let you know this project is for Java driver bugs or feature requests. The best place for questions regarding MongoDB usage or the Java driver specifics is the mongodb-user mailing list or stackoverflow as you will reach a boarder audience there. I know the Spring data community also monitors questions tagged in StackOverflow. If your business requires an answer from MongoDB within a set time frame then we do offer production support.

I hope that helps,

Ross

Generated at Thu Feb 08 08:56:50 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.