mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
fix setting load bugf
This commit is contained in:
parent
082a8f67ac
commit
d0641fc7e6
@ -22,7 +22,6 @@ import org.dromara.hutool.db.sql.SqlLog;
|
||||
import org.dromara.hutool.db.sql.filter.SqlLogFilter;
|
||||
import org.dromara.hutool.log.level.Level;
|
||||
import org.dromara.hutool.setting.Setting;
|
||||
import org.dromara.hutool.setting.props.Props;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@ -158,14 +157,12 @@ public class SettingConfigParser implements ConfigParser {
|
||||
}
|
||||
|
||||
// 自定义连接属性
|
||||
final Props connProps = new Props();
|
||||
final Set<String> keys = setting.keySet();
|
||||
for (final String key : keys) {
|
||||
if (key.startsWith(CONNECTION_PREFIX)) {
|
||||
connProps.set(StrUtil.subSuf(key, CONNECTION_PREFIX.length()), setting.remove(key));
|
||||
dbConfig.addConnProps(StrUtil.subSuf(key, CONNECTION_PREFIX.length()), setting.remove(key));
|
||||
}
|
||||
}
|
||||
dbConfig.setConnProps(connProps);
|
||||
|
||||
// 池属性
|
||||
dbConfig.setPoolProps(setting.toProps());
|
||||
|
@ -0,0 +1,18 @@
|
||||
package org.dromara.hutool.db;
|
||||
|
||||
import org.dromara.hutool.db.config.DbConfig;
|
||||
import org.dromara.hutool.db.config.SettingConfigParser;
|
||||
import org.dromara.hutool.setting.Setting;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IssueI9B98CTest {
|
||||
|
||||
@Test
|
||||
void settingConfigParserTest() {
|
||||
final SettingConfigParser settingConfigParser = SettingConfigParser.of(new Setting("config/issueI9B98C.setting"));
|
||||
final DbConfig config = settingConfigParser.parse(null);
|
||||
Assertions.assertEquals("jdbc:sqlite:test.db", config.getUrl());
|
||||
Assertions.assertEquals("true", config.getConnProps().getProperty("remarks"));
|
||||
}
|
||||
}
|
3
hutool-db/src/test/resources/config/issueI9B98C.setting
Normal file
3
hutool-db/src/test/resources/config/issueI9B98C.setting
Normal file
@ -0,0 +1,3 @@
|
||||
# 默认数据源
|
||||
url = jdbc:sqlite:test.db
|
||||
remarks = true
|
@ -387,7 +387,12 @@ public class Setting extends AbsSetting implements Map<String, String> {
|
||||
for (final Entry<String, LinkedHashMap<String, String>> groupEntry : this.groupedMap.entrySet()) {
|
||||
group = groupEntry.getKey();
|
||||
for (final Entry<String, String> entry : groupEntry.getValue().entrySet()) {
|
||||
props.setProperty(StrUtil.isEmpty(group) ? entry.getKey() : group + CharUtil.DOT + entry.getKey(), entry.getValue());
|
||||
// issue#I9B98C,忽略null的键值对
|
||||
final String key = entry.getKey();
|
||||
final String value = entry.getValue();
|
||||
if(null != key && null != value){
|
||||
props.setProperty(StrUtil.isEmpty(group) ? key : group + CharUtil.DOT + key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return props;
|
||||
|
Loading…
x
Reference in New Issue
Block a user