|
|
@ -16,12 +16,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.boot.autoconfigure.mongo;
|
|
|
|
package org.springframework.boot.autoconfigure.mongo;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
|
|
|
|
|
|
|
import com.mongodb.DBPort;
|
|
|
|
import com.mongodb.DBPort;
|
|
|
|
import com.mongodb.MongoClient;
|
|
|
|
import com.mongodb.MongoClient;
|
|
|
|
import com.mongodb.MongoClientURI;
|
|
|
|
import com.mongodb.MongoClientURI;
|
|
|
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.net.UnknownHostException;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Configuration properties for Mongo.
|
|
|
|
* Configuration properties for Mongo.
|
|
|
@ -33,69 +34,68 @@ import java.net.UnknownHostException;
|
|
|
|
@ConfigurationProperties(prefix = "spring.data.mongodb")
|
|
|
|
@ConfigurationProperties(prefix = "spring.data.mongodb")
|
|
|
|
public class MongoProperties {
|
|
|
|
public class MongoProperties {
|
|
|
|
|
|
|
|
|
|
|
|
private String host;
|
|
|
|
private String host;
|
|
|
|
|
|
|
|
|
|
|
|
private int port = DBPort.PORT;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String uri = "mongodb://localhost/test";
|
|
|
|
private int port = DBPort.PORT;
|
|
|
|
|
|
|
|
|
|
|
|
private String database;
|
|
|
|
private String uri = "mongodb://localhost/test";
|
|
|
|
|
|
|
|
|
|
|
|
private String gridFsDatabase;
|
|
|
|
private String database;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private String gridFsDatabase;
|
|
|
|
|
|
|
|
|
|
|
|
public String getHost() {
|
|
|
|
public String getHost() {
|
|
|
|
return this.host;
|
|
|
|
return this.host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setHost(String host) {
|
|
|
|
public void setHost(String host) {
|
|
|
|
this.host = host;
|
|
|
|
this.host = host;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getDatabase() {
|
|
|
|
public String getDatabase() {
|
|
|
|
return this.database;
|
|
|
|
return this.database;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setDatabase(String database) {
|
|
|
|
public void setDatabase(String database) {
|
|
|
|
this.database = database;
|
|
|
|
this.database = database;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getUri() {
|
|
|
|
public String getUri() {
|
|
|
|
return this.uri;
|
|
|
|
return this.uri;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setUri(String uri) {
|
|
|
|
public void setUri(String uri) {
|
|
|
|
this.uri = uri;
|
|
|
|
this.uri = uri;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public int getPort() {
|
|
|
|
public int getPort() {
|
|
|
|
return this.port;
|
|
|
|
return this.port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setPort(int port) {
|
|
|
|
public void setPort(int port) {
|
|
|
|
this.port = port;
|
|
|
|
this.port = port;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getGridFsDatabase() {
|
|
|
|
public String getGridFsDatabase() {
|
|
|
|
return gridFsDatabase;
|
|
|
|
return this.gridFsDatabase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void setGridFsDatabase(String gridFsDatabase) {
|
|
|
|
public void setGridFsDatabase(String gridFsDatabase) {
|
|
|
|
this.gridFsDatabase = gridFsDatabase;
|
|
|
|
this.gridFsDatabase = gridFsDatabase;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public String getMongoClientDatabase() {
|
|
|
|
public String getMongoClientDatabase() {
|
|
|
|
if (this.database != null) {
|
|
|
|
if (this.database != null) {
|
|
|
|
return this.database;
|
|
|
|
return this.database;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new MongoClientURI(this.uri).getDatabase();
|
|
|
|
return new MongoClientURI(this.uri).getDatabase();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MongoClient createMongoClient() throws UnknownHostException {
|
|
|
|
public MongoClient createMongoClient() throws UnknownHostException {
|
|
|
|
if (this.host != null) {
|
|
|
|
if (this.host != null) {
|
|
|
|
return new MongoClient(this.host, this.port);
|
|
|
|
return new MongoClient(this.host, this.port);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new MongoClient(new MongoClientURI(this.uri));
|
|
|
|
return new MongoClient(new MongoClientURI(this.uri));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|