use of cn.hutool.setting.Setting in project hutool by looly.
the class MongoDS method initSingle.
/**
* 初始化<br>
* 设定文件中的host和端口有三种形式:
*
* <pre>
* host = host:port
* </pre>
*
* <pre>
* host = host
* port = port
* </pre>
*
* <pre>
* host = host
* </pre>
*/
public synchronized void initSingle() {
if (setting == null) {
try {
setting = new Setting(MONGO_CONFIG_PATH, true);
} catch (Exception e) {
// 在single模式下,可以没有配置文件。
}
}
String group = StrUtil.EMPTY;
if (null == this.serverAddress) {
// 存在唯一分组
if (groups != null && groups.length == 1) {
group = groups[0];
}
serverAddress = createServerAddress(group);
}
final MongoCredential credentail = createCredentail(group);
try {
if (null == credentail) {
mongo = new MongoClient(serverAddress, buildMongoClientOptions(group));
} else {
mongo = new MongoClient(serverAddress, credentail, buildMongoClientOptions(group));
}
} catch (Exception e) {
throw new DbRuntimeException(StrUtil.format("Init MongoDB pool with connection to [{}] error!", serverAddress), e);
}
log.info("Init MongoDB pool with connection to [{}]", serverAddress);
}
Aggregations