fix setting load bugf

This commit is contained in:
Looly 2024-03-25 12:10:06 +08:00
parent 082a8f67ac
commit d0641fc7e6
4 changed files with 28 additions and 5 deletions

View File

@ -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());

View File

@ -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"));
}
}

View File

@ -0,0 +1,3 @@
# 默认数据源
url = jdbc:sqlite:test.db
remarks = true

View File

@ -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;