Registry error: MongoDB exception: com.mongodb.MongoSocketOpenException: Exception opening socket
search cancel

Registry error: MongoDB exception: com.mongodb.MongoSocketOpenException: Exception opening socket


Article ID: 277833


Updated On:


Service Virtualization


Getting this exception on MongoDB Service in the Registry log:

2023-11-29T03:53:20,049Z (22:53) [Thread-17] INFO  org.mongodb.driver.cluster     - Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
2023-11-29T03:53:20,051Z (22:53) [cluster-ClusterId{value='<cluster-ClusterId>', 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 ~[mongo-java-driver-3.12.14.jar:?]
    at ~[mongo-java-driver-3.12.14.jar:?]
    at com.mongodb.internal.connection.DefaultServerMonitor$ [mongo-java-driver-3.12.14.jar:?]
    at [?:1.8.0_352]
Caused by: Connection refused (Connection refused)
    at Method) ~[?:1.8.0_352]
    at ~[?:1.8.0_352]
    at ~[?:1.8.0_352]
    at ~[?:1.8.0_352]
    at ~[?:1.8.0_352]
    at ~[?:1.8.0_352]
    at com.mongodb.internal.connection.SocketStreamHelper.initialize( ~[mongo-java-driver-3.12.14.jar:?]
    at com.mongodb.internal.connection.SocketStream.initializeSocket( ~[mongo-java-driver-3.12.14.jar:?]
    at ~[mongo-java-driver-3.12.14.jar:?]
    ... 3 more


Nothing is down, just want to know what this exception is.


DevTest 10.7.2 SP3




When the MongoDB driver is included in the classpath of a Spring Boot application, Spring Boot will automatically try to connect to a MongoDB server. This assumes that the server is accessible locally at the default host (localhost) and port (27017). If the MongoDB server is not running or not available at the specified location, this attempt results in an error.

To enable auto-configurations for databases in a Spring Boot application, including the relevant database driver dependencies is essential. Specifically, for MongoDB, including the mongo-java-driver is sufficient, and Spring Boot will handle most configurations automatically. For other databases, we must include the corresponding driver dependencies and configure connection properties as well. If we wish to exclude certain auto-configurations, we can use the spring.autoconfigure.exclude property, specifying the fully qualified names of the classes we want to exclude.

For example, to exclude MongoDB auto-configuration, we can set spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration.

To disable MongoDB auto configuration please follow below steps:

1. Stop Registry Service
2. Delete all Registry log files.
3. Add below property in RegistryService.vmoptions
4. Start Registry service.

Will not see the exception messages in the log file.