Ing. Luca Stucchi
Ing. Luca Stucchi

Reputation: 3277

Spring Data MongoDB - Always connecting with default parameters

I am using MongoDB 3.0.0 with Spring, accessing with spring-data-mongodb and mongo-java-driver

<dependency>
    <groupId>org.springframework.data</groupId>
    <artifactId>spring-data-mongodb</artifactId>
    <version>1.7.0.RELEASE</version>
</dependency>

<dependency>
    <groupId>org.mongodb</groupId>
    <artifactId>mongo-java-driver</artifactId>
    <version>3.0.2</version>
</dependency>

In test environment, I perform JUnit tests on object validation only, so I don't load any MongoTemplate, nor any mongo-related configuration.

For some reason, I always get in the log:

2015-06-22 15:06:17,049 GMT [main] (SLF4JLogger.java:71) INFO  driver.cluster: Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=50}
2015-06-22 15:06:17,290 GMT [cluster-ClusterId{value='558808495d12e1d8bcc6ef19', description='null'}-localhost:27017] (SLF4JLogger.java:71) INFO  driver.connection: Opened connection [connectionId{localValue:1, serverValue:55}] to localhost:27017
2015-06-22 15:06:17,290 GMT [cluster-ClusterId{value='558808495d12e1d8bcc6ef19', description='null'}-localhost:27017] (SLF4JLogger.java:71) INFO  driver.cluster: Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 0, 0]}, minWireVersion=0, maxWireVersion=3, electionId=null, maxDocumentSize=16777216, roundTripTimeNanos=434000}

Is it possible that in the spring-data-mongodb I get a Bean definition that causes the connection described in the log ? Is there any way to prevent it ?

Upvotes: 0

Views: 1269

Answers (1)

ErikHH
ErikHH

Reputation: 93

I think Spring loads it automatically. You can disable it by disabling auto configuration for the following classes

@EnableAutoConfiguration(exclude = {
  org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,
  org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration })

Upvotes: 1

Related Questions