use of cn.hutool.setting.Setting in project hutool by looly.
the class SettingTest method settingTestForAbsPath.
@Test
@Ignore
public void settingTestForAbsPath() {
Setting setting = new Setting("d:/test.setting", true);
String driver = setting.getByGroup("driver", "demo");
Assert.assertEquals(driver, "com.mysql.jdbc.Driver");
String user = setting.getByGroup("user", "demo");
Assert.assertEquals(user, "rootcom.mysql.jdbc.Driver");
}
use of cn.hutool.setting.Setting in project hutool by looly.
the class Profile method getSetting.
// -------------------------------------------------------------------------------- Constructor end
/**
* 获取当前环境下的配置文件
*
* @param name 文件名,如果没有扩展名,默认为.setting
* @return 当前环境下配置文件
*/
public Setting getSetting(String name) {
String nameForProfile = fixNameForProfile(name);
Setting setting = settingMap.get(nameForProfile);
if (null == setting) {
setting = new Setting(nameForProfile, this.charset, this.useVar);
settingMap.put(nameForProfile, setting);
}
return setting;
}
use of cn.hutool.setting.Setting in project hutool by looly.
the class MongoDS method initCloud.
/**
* 初始化集群<br>
* 集群的其它客户端设定参数使用全局设定<br>
* 集群中每一个实例成员用一个group表示,例如:
*
* <pre>
* user = test1
* pass = 123456
* database = test
* [db0]
* host = 192.168.1.1:27117
* [db1]
* host = 192.168.1.1:27118
* [db2]
* host = 192.168.1.1:27119
* </pre>
*/
public synchronized void initCloud() {
if (groups == null || groups.length == 0) {
throw new DbRuntimeException("Please give replication set groups!");
}
if (setting == null) {
// 若未指定配置文件,则使用默认配置文件
setting = new Setting(MONGO_CONFIG_PATH, true);
}
final List<ServerAddress> addrList = new ArrayList<>();
for (String group : groups) {
addrList.add(createServerAddress(group));
}
final MongoCredential credentail = createCredentail(StrUtil.EMPTY);
try {
if (null == credentail) {
mongo = new MongoClient(addrList, buildMongoClientOptions(StrUtil.EMPTY));
} else {
mongo = new MongoClient(addrList, credentail, buildMongoClientOptions(StrUtil.EMPTY));
}
} catch (Exception e) {
log.error(e, "Init MongoDB connection error!");
return;
}
log.info("Init MongoDB cloud Set pool with connection to {}", addrList);
}
use of cn.hutool.setting.Setting in project hutool by looly.
the class MongoDS method createServerAddress.
// --------------------------------------------------------------------------- Private method start
/**
* 创建ServerAddress对象,会读取配置文件中的相关信息
*
* @param group 分组,如果为{@code null}或者""默认为无分组
* @return ServerAddress
*/
private ServerAddress createServerAddress(String group) {
final Setting setting = checkSetting();
if (group == null) {
group = StrUtil.EMPTY;
}
final String tmpHost = setting.getByGroup("host", group);
if (StrUtil.isBlank(tmpHost)) {
throw new NotInitedException("Host name is empy of group: {}", group);
}
final int defaultPort = setting.getInt("port", group, 27017);
return new ServerAddress(NetUtil.buildInetSocketAddress(tmpHost, defaultPort));
}
use of cn.hutool.setting.Setting in project hutool by looly.
the class MongoDS method createCredentail.
/**
* 创建{@link MongoCredential},用于服务端验证<br>
* 此方法会首先读取指定分组下的属性,用户没有定义则读取空分组下的属性
*
* @param group 分组
* @return {@link MongoCredential},如果用户未指定用户名密码返回null
* @since 4.1.20
*/
private MongoCredential createCredentail(String group) {
final Setting setting = this.setting;
if (null == setting) {
return null;
}
final String user = setting.getStr("user", group, setting.getStr("user"));
final String pass = setting.getStr("pass", group, setting.getStr("pass"));
final String database = setting.getStr("database", group, setting.getStr("database"));
return createCredentail(user, database, pass);
}
Aggregations