初めてSpringを使用していて、RESTful APIを開発しようとしています。なぜ私はmongoデータベースへの接続を4つまで開くのですか?
[ restartedMain] org.mongodb.driver.cluster : Cluster created with settings {hosts=[127.0.0.1:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[127.0.0.1:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:1, serverValue:1}] to 127.0.0.1:27017
[127.0.0.1:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=127.0.0.1:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 4]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=1907739}
[ restartedMain] org.mongodb.driver.cluster : Cluster created with settings {hosts=[localhost:27017], mode=SINGLE, requiredClusterType=UNKNOWN, serverSelectionTimeout='30000 ms', maxWaitQueueSize=500}
[localhost:27017] org.mongodb.driver.connection : Opened connection [connectionId{localValue:2, serverValue:2}] to localhost:27017
[localhost:27017] org.mongodb.driver.cluster : Monitor thread successfully connected to server with description ServerDescription{address=localhost:27017, type=STANDALONE, state=CONNECTED, ok=true, version=ServerVersion{versionList=[3, 4, 4]}, minWireVersion=0, maxWireVersion=5, maxDocumentSize=16777216, roundTripTimeNanos=1145793}
[ restartedMain] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:3}] to localhost:27017
[ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
[ restartedMain] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8080 (http)
[ restartedMain] org.mongodb.driver.connection : Opened connection [connectionId{localValue:4, serverValue:4}] to 127.0.0.1:27017
マイモンゴ構成:
@Configuration
@EnableMongoRepositories(basePackages="com.api.repo")
class MongoConfig extends AbstractMongoConfiguration {
@Value("${spring.data.mongodb.host}")
private String url;
@Value("${spring.data.mongodb.port}")
private int port;
@Value("${spring.data.mongodb.database}")
private String db;
@Override
protected String getDatabaseName() {
return db;
}
@Override
public Mongo mongo() throws Exception {
// return new Fongo("meh").getMongo();
return new MongoClient(url, port);
}
@Override
protected Collection<String> getMappingBasePackages() {
return Arrays.asList("com.api");
}
私はMongoClientをsingleton'private static finalとして設定した場合、Mongo mongo = new MongoClient(url、port); '例外が発生します。 – anat0lius