I am learning java and Spring boot 2
So my problem is:
2018-07-09 11:40:24.816 INFO 20196 --- [localhost:27017] 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:62) ~[mongo-java-driver-3.6.4.jar:na]
at com.mongodb.connection.InternalStreamConnection.open (InternalStreamConnection.java:126) ~[mongo-java-driver-3.6.4.jar:na]
at com.mongodb.connection.DefaultServerMonitor$ServerMonitorRunnable.run (DefaultServerMonitor.java:114) ~[mongo-java-driver-3.6.4.jar:na]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171] Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_171]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_171]
at java.net.AbstractPlainSocketImpl.connectToAddress (AbstractPlainSocketImpl.java:206) ~[na:1.8.0_171]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_171]
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_171]
at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_171]
at com.mongodb.connection.SocketStreamHelper.initialize (SocketStreamHelper.java:59) ~[mongo-java-driver-3.6.4.jar:na]
at com.mongodb.connection.SocketStream.open(SocketStream.java:57) ~[mongo-java-driver-3.6.4.jar:na]
... 3 common frames omitted
2018-07-09 11:40:25.164 INFO 20196 --- [ main] org.mongodb.driver.cluster: Cluster description not yet available. Waiting for 30000 ms before timing out
So when Spring Boot 2 is Maven build app it stuck because of absent MongoDB server and trying to connect 3 time with timeout 30000ms, then stuck...
So I want to init this connection, after finishing of Maven build, from runtime with external config parameter, and then with @shedules monitoring check if MongoDB alive, and reconnect if it lost.
What I found for SQL is excluding autoconfiguration from topic but I dont know which file is configure MongoDB from this link. And may be I must configure it like a @PostConstruct @bean conf files? (please suggest me example if it present and possibility to do this opportunity)
Thank you in advance!
for now I take an example of db routers:
@SpringBootApplication(exclude =
{org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.class
,org.springframework.boot.autoconfigure.data.mongo
.MongoDataAutoConfiguration.class})
public class Application {
exclude 2 files from autoconfigure, wrote some class for setup my properties, but I still do not know how to delay an effort of connection!