我在Spring中使用MongoDB 3.0.0,使用spring-data-mongodb
和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>
在测试环境中,我只对对象验证执行JUnit测试,因此我不会加载任何MongoTemplate
,也不会加载任何与mongo相关的配置。
出于某种原因,我总是进入日志:
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}
是否有可能在spring-data-mongodb
中我获得了导致日志中描述的连接的Bean定义?有什么办法可以预防吗?
答案 0 :(得分:1)
我认为Spring会自动加载它。 您可以通过禁用以下类的自动配置来禁用它
@EnableAutoConfiguration(exclude = {
org.springframework.boot.autoconfigure.mongo.MongoAutoConfiguration,
org.springframework.boot.autoconfigure.mongo.MongoDataAutoConfiguration })