mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
GlobalDbSetting优化默认配置读取规则,优先读取文件而非jar中的文件(issue#900@Github)
This commit is contained in:
parent
5f57da864d
commit
b116be492a
@ -2,11 +2,13 @@
|
|||||||
# 🚀Changelog
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.36(2025-01-10)
|
# 5.8.36(2025-01-12)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【crypto 】 增加BCUtil.decodeECPrivateKey方法(issue#3829@Github)
|
* 【crypto 】 增加BCUtil.decodeECPrivateKey方法(issue#3829@Github)
|
||||||
* 【core 】 增加HtmlUtil.cleanEmptyTag方法(pr#3838@Github)
|
* 【core 】 增加HtmlUtil.cleanEmptyTag方法(pr#3838@Github)
|
||||||
|
* 【db 】 GlobalDbSetting优化默认配置读取规则,优先读取文件而非jar中的文件(issue#900@Github)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
* 【aop 】 修复ProxyUtil可能的空指针问题(issue#IBF20Z@Gitee)
|
* 【aop 】 修复ProxyUtil可能的空指针问题(issue#IBF20Z@Gitee)
|
||||||
* 【core 】 修复XmlUtil转义调用方法错误问题,修复XmlEscape未转义单引号问题(pr#3837@Github)
|
* 【core 】 修复XmlUtil转义调用方法错误问题,修复XmlEscape未转义单引号问题(pr#3837@Github)
|
||||||
|
@ -79,6 +79,9 @@ public class FileResource implements Resource, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream getStream() throws NoResourceException {
|
public InputStream getStream() throws NoResourceException {
|
||||||
|
if (!this.file.exists()) {
|
||||||
|
throw new NoResourceException("File [{}] not exist!", this.file.getAbsolutePath());
|
||||||
|
}
|
||||||
return FileUtil.getInputStream(this.file);
|
return FileUtil.getInputStream(this.file);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package cn.hutool.db;
|
package cn.hutool.db;
|
||||||
|
|
||||||
import cn.hutool.core.io.resource.NoResourceException;
|
import cn.hutool.core.io.resource.NoResourceException;
|
||||||
|
import cn.hutool.core.util.ArrayUtil;
|
||||||
import cn.hutool.db.sql.SqlLog;
|
import cn.hutool.db.sql.SqlLog;
|
||||||
import cn.hutool.log.level.Level;
|
import cn.hutool.log.level.Level;
|
||||||
import cn.hutool.setting.Setting;
|
import cn.hutool.setting.Setting;
|
||||||
@ -83,20 +84,30 @@ public class GlobalDbConfig {
|
|||||||
throw new NoResourceException("Customize db setting file [{}] not found !", dbSettingPath);
|
throw new NoResourceException("Customize db setting file [{}] not found !", dbSettingPath);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
try {
|
setting = tryDefaultDbSetting();
|
||||||
setting = new Setting(DEFAULT_DB_SETTING_PATH, true);
|
|
||||||
} catch (NoResourceException e) {
|
|
||||||
// 尝试ClassPath下直接读取配置文件
|
|
||||||
try {
|
|
||||||
setting = new Setting(DEFAULT_DB_SETTING_PATH2, true);
|
|
||||||
} catch (NoResourceException e2) {
|
|
||||||
throw new NoResourceException("Default db setting [{}] or [{}] in classpath not found !", DEFAULT_DB_SETTING_PATH, DEFAULT_DB_SETTING_PATH2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return setting;
|
return setting;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取自定义或默认位置数据库配置{@link Setting}
|
||||||
|
*
|
||||||
|
* @return 数据库配置
|
||||||
|
* @since 5.8.36
|
||||||
|
*/
|
||||||
|
private static Setting tryDefaultDbSetting() {
|
||||||
|
final String[] defaultDbSettingPaths = {"file:" + DEFAULT_DB_SETTING_PATH, "file:" + DEFAULT_DB_SETTING_PATH2, DEFAULT_DB_SETTING_PATH, DEFAULT_DB_SETTING_PATH2};
|
||||||
|
for (final String settingPath : defaultDbSettingPaths) {
|
||||||
|
try {
|
||||||
|
return new Setting(settingPath, true);
|
||||||
|
} catch (final NoResourceException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new NoResourceException("Default db settings [{}] in classpath not found !", ArrayUtil.join(defaultDbSettingPaths, ","));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 设置全局配置:是否通过debug日志显示SQL
|
* 设置全局配置:是否通过debug日志显示SQL
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user