Renamed field to not match method name. Close mongoconnection.
This commit is contained in:
@@ -51,7 +51,7 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
|
|||||||
@Autowired(required = false)
|
@Autowired(required = false)
|
||||||
private MongoClientOptions options;
|
private MongoClientOptions options;
|
||||||
|
|
||||||
private Mongo mongo;
|
private Mongo mongoConnection;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getDatabaseName() {
|
public String getDatabaseName() {
|
||||||
@@ -63,8 +63,8 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
|
|||||||
*/
|
*/
|
||||||
@PreDestroy
|
@PreDestroy
|
||||||
public void close() {
|
public void close() {
|
||||||
if (this.mongo != null) {
|
if (this.mongoConnection != null) {
|
||||||
this.mongo.close();
|
this.mongoConnection.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -74,16 +74,25 @@ public class MongoConfiguration extends AbstractMongoConfiguration {
|
|||||||
public Mongo mongo() throws UnknownHostException {
|
public Mongo mongo() throws UnknownHostException {
|
||||||
final MongoClientURI uri = new MongoClientURI(properties.getUri(), createBuilderOutOfOptions(options));
|
final MongoClientURI uri = new MongoClientURI(properties.getUri(), createBuilderOutOfOptions(options));
|
||||||
|
|
||||||
|
try {
|
||||||
if (properties.getPort() != null) {
|
if (properties.getPort() != null) {
|
||||||
LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0), properties.getPort());
|
LOG.debug("Create mongo by properties (host: {}, port: {})", uri.getHosts().get(0),
|
||||||
this.mongo = new MongoClient(Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())),
|
properties.getPort());
|
||||||
|
this.mongoConnection = new MongoClient(
|
||||||
|
Arrays.asList(new ServerAddress(uri.getHosts().get(0), properties.getPort())),
|
||||||
uri.getOptions());
|
uri.getOptions());
|
||||||
} else {
|
} else {
|
||||||
LOG.debug("Create mongo by URI : {}", uri);
|
LOG.debug("Create mongo by URI : {}", uri);
|
||||||
this.mongo = new MongoClient(uri);
|
this.mongoConnection = new MongoClient(uri);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (this.mongoConnection != null) {
|
||||||
|
this.mongoConnection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.mongo;
|
}
|
||||||
|
|
||||||
|
return this.mongoConnection;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user