I have tried passing the setting the connection spring in the application.properties → spring.data.mongodb.uri=
I am getting the below errors:
at com.mongodb.internal.connection.InternalStreamConnection.translateReadException(InternalStreamConnection.java:568) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveMessage(InternalStreamConnection.java:447) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.receiveCommandMessageResponse(InternalStreamConnection.java:298) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.sendAndReceive(InternalStreamConnection.java:258) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.CommandHelper.sendAndReceive(CommandHelper.java:83) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.CommandHelper.executeCommand(CommandHelper.java:33) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initializeConnectionDescription(InternalStreamConnectionInitializer.java:103) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.InternalStreamConnectionInitializer.initialize(InternalStreamConnectionInitializer.java:60) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.InternalStreamConnection.open(InternalStreamConnection.java:128) ~[mongodb-driver-core-4.0.4.jar:na]
at com.mongodb.internal.connection.DefaultServerMonitor$ServerMonitorRunnable.run(DefaultServerMonitor.java:117) ~[mongodb-driver-core-4.0.4.jar:na]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_73]
Haven’t tried. I am able to connect to the cluster with python. I can perform CRUD operations fine with python without any issues. The issue I am having is connecting to the Cluster with Spring, seems like a SSL issue, but I am not forsure?
Know I am getting this error:
Servlet.service() for servlet [dispatcherServlet] in context with path threw exception [Handler dispatch failed; nested exception is java.lang.NoClassDefFoundError: com/mongodb/connection/DefaultClusterFactory] with root cause java.lang.ClassNotFoundException: com.mongodb.connection.DefaultClusterFactory
I can connect to database on a replica-set on localhost and query using MongoTemplate API. It is a Spring Boot application (2.3.1) with similar Spring configuration and Java Driver (4.0.4).
The MongoClient is created using the following:
MongoClient mongoClient = MongoClients.create(
MongoClientSettings.builder()
.applyToClusterSettings(builder ->
builder.hosts(Arrays.asList(
new ServerAddress("localhost", 30001),
new ServerAddress("localhost", 30002),
new ServerAddress("localhost", 30003))))
.build());
Could you try with com.mongodb.MongoClientURI and the SRV string?
MongoClientURI uri = new MongoClientURI( "mongodb+srv://UserName:Password@mongastreamlistener-ja2vb.mongodb.net/database1?retryWrites=true&connectTimeoutMS=5000" ) ;
MongoClient client = new MongoClient( uri ) ;