mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
修复SettingLoader
load未抛出异常导致配置文件无法正常遍历的问题(pr#3868@Github)
This commit is contained in:
parent
4ef8814c14
commit
1c0b6c3da1
@ -2,13 +2,14 @@
|
||||
# 🚀Changelog
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.37(2025-02-18)
|
||||
# 5.8.37(2025-02-24)
|
||||
|
||||
### 🐣新特性
|
||||
* 【json 】 ObjectMapper删除重复trim(pr#3859@Github)
|
||||
* 【core 】 `FileWriter`增加方法,可选是否追加换行符(issue#3858@Github)
|
||||
|
||||
### 🐞Bug修复
|
||||
* 【setting】 修复`SettingLoader`load未抛出异常导致配置文件无法正常遍历的问题(pr#3868@Github)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
# 5.8.36(2025-02-18)
|
||||
|
@ -1351,11 +1351,11 @@ public class FileUtil extends PathUtil {
|
||||
if (null == classPath) {
|
||||
// throw new NullPointerException("ClassPath is null !");
|
||||
// 在jar运行模式中,ClassPath有可能获取不到,此时返回原始相对路径(此时获取的文件为相对工作目录)
|
||||
return path;
|
||||
return normalPath;
|
||||
}
|
||||
|
||||
// 资源不存在的情况下使用标准化路径有问题,使用原始路径拼接后标准化路径
|
||||
return normalize(classPath.concat(Objects.requireNonNull(path)));
|
||||
return normalize(classPath.concat(Objects.requireNonNull(normalPath)));
|
||||
}
|
||||
|
||||
/**
|
||||
|
10
hutool-db/src/test/java/cn/hutool/db/GlobalDbConfigTest.java
Normal file
10
hutool-db/src/test/java/cn/hutool/db/GlobalDbConfigTest.java
Normal file
@ -0,0 +1,10 @@
|
||||
package cn.hutool.db;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class GlobalDbConfigTest {
|
||||
@Test
|
||||
void createDbSettingTest(){
|
||||
GlobalDbConfig.createDbSetting();
|
||||
}
|
||||
}
|
@ -2,20 +2,13 @@ package cn.hutool.setting;
|
||||
|
||||
import cn.hutool.core.io.FileUtil;
|
||||
import cn.hutool.core.io.IoUtil;
|
||||
import cn.hutool.core.io.resource.NoResourceException;
|
||||
import cn.hutool.core.io.resource.Resource;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.util.CharUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.ReUtil;
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import cn.hutool.core.util.SystemPropsUtil;
|
||||
import cn.hutool.core.util.*;
|
||||
import cn.hutool.log.Log;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -73,19 +66,22 @@ public class SettingLoader {
|
||||
*
|
||||
* @param resource 配置文件URL
|
||||
* @return 加载是否成功
|
||||
* @throws NoResourceException 如果资源不存在,抛出此异常
|
||||
*/
|
||||
public boolean load(Resource resource) {
|
||||
public boolean load(Resource resource) throws NoResourceException{
|
||||
if (resource == null) {
|
||||
throw new NullPointerException("Null setting url define!");
|
||||
}
|
||||
log.debug("Load setting file [{}]", resource);
|
||||
InputStream settingStream = null;
|
||||
try {
|
||||
settingStream = resource.getStream();
|
||||
load(settingStream);
|
||||
log.debug("Load setting file [{}]", resource);
|
||||
} catch (Exception e) {
|
||||
log.error(e, "Load setting error!");
|
||||
return false;
|
||||
if(e instanceof NoResourceException){
|
||||
throw (NoResourceException)e;
|
||||
}
|
||||
throw new NoResourceException(e);
|
||||
} finally {
|
||||
IoUtil.close(settingStream);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user