Renamed field to not match method name. Close mongoconnection.

This commit is contained in:
Kai Zimmermann
2016-01-27 11:56:38 +01:00
parent fbcc0b8de0
commit ffacf8cf68

View File

@@ -51,7 +51,7 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
@Autowired(required = false)
private MongoClientOptions options;
private Mongo mongo;
private Mongo mongoConnection;
@Override
public String getDatabaseName() {
@@ -63,8 +63,8 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
*/
@PreDestroy
public void close() {
if (this.mongo != null) {
this.mongo.close();
if (this.mongoConnection != null) {
this.mongoConnection.close();
}
}
@@ -74,16 +74,25 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
public Mongo mongo() throws UnknownHostException {
final MongoClientURI uri = new MongoClientURI(properties.getUri(), createBuilderOutOfOptions(options));
if (properties.getPort() != null) {
LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0), properties.getPort());
this.mongo = new MongoClient(Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())),
uri.getOptions());
} else {
LOG.debug("Create mongo by URI : {}", uri);
this.mongo = new MongoClient(uri);
try {
if (properties.getPort() != null) {
LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0),
properties.getPort());
this.mongoConnection = new MongoClient(
Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())),
uri.getOptions());
} else {
LOG.debug("Create mongo by URI : {}", uri);
this.mongoConnection = new MongoClient(uri);
}
} finally {
if (this.mongoConnection != null) {
this.mongoConnection.close();
}
}
return this.mongo;
return this.mongoConnection;
}
/*