diff --git a/CHANGELOG.md b/CHANGELOG.md index fe587a28a..5db9d4c3b 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) diff --git a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java index d40086168..09d1b7d3f 100755 --- a/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java +++ b/hutool-core/src/main/java/cn/hutool/core/io/FileUtil.java @@ -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))); } /** diff --git a/hutool-db/src/test/java/cn/hutool/db/GlobalDbConfigTest.java b/hutool-db/src/test/java/cn/hutool/db/GlobalDbConfigTest.java new file mode 100644 index 000000000..ffb16d8b0 --- /dev/null +++ b/hutool-db/src/test/java/cn/hutool/db/GlobalDbConfigTest.java @@ -0,0 +1,10 @@ +package cn.hutool.db; + +import org.junit.jupiter.api.Test; + +public class GlobalDbConfigTest { + @Test + void createDbSettingTest(){ + GlobalDbConfig.createDbSetting(); + } +} diff --git a/hutool-db/src/test/resources/config/example/db-example-c3p0.setting b/hutool-db/src/test/resources/config/example/db-example-c3p0.setting index eae49198d..10ea0ee62 100644 --- a/hutool-db/src/test/resources/config/example/db-example-c3p0.setting +++ b/hutool-db/src/test/resources/config/example/db-example-c3p0.setting @@ -51,4 +51,4 @@ idleConnectionTestPeriod = 0 # c3p0全局的PreparedStatements缓存的大小。如果maxStatements与maxStatementsPerConnection均为0,则缓存不生效,只要有一个不为0,则语句的缓存就能生效。如果默认值: 0 maxStatements = 0 # maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。默认值: 0 -maxStatementsPerConnection = 0 \ No newline at end of file +maxStatementsPerConnection = 0 diff --git a/hutool-db/src/test/resources/config/example/db-example-dbcp.setting b/hutool-db/src/test/resources/config/example/db-example-dbcp.setting index 8ec36fc75..0ca386f15 100644 --- a/hutool-db/src/test/resources/config/example/db-example-dbcp.setting +++ b/hutool-db/src/test/resources/config/example/db-example-dbcp.setting @@ -48,4 +48,4 @@ testOnBorrow = false # (boolean) 指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串 testOnReturn = false # (boolean) 指明连接是否被空闲连接回收器( 如果有) 进行检验。 如果检测失败, 则连接将被从池中去除。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串 -testWhileIdle = false \ No newline at end of file +testWhileIdle = false diff --git a/hutool-db/src/test/resources/config/example/db-example-druid.setting b/hutool-db/src/test/resources/config/example/db-example-druid.setting index fb27f29c5..9fbaf2b3e 100644 --- a/hutool-db/src/test/resources/config/example/db-example-druid.setting +++ b/hutool-db/src/test/resources/config/example/db-example-druid.setting @@ -52,4 +52,4 @@ connectionInitSqls = SELECT 1 # 属性类型是字符串,通过别名的方式配置扩展插件, 常用的插件有: 监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall filters = stat # 类型是List, 如果同时配置了filters和proxyFilters, 是组合关系,并非替换关系 -proxyFilters = \ No newline at end of file +proxyFilters = diff --git a/hutool-db/src/test/resources/config/example/db-example-hikari.setting b/hutool-db/src/test/resources/config/example/db-example-hikari.setting index 33088a177..b5647fd24 100644 --- a/hutool-db/src/test/resources/config/example/db-example-hikari.setting +++ b/hutool-db/src/test/resources/config/example/db-example-hikari.setting @@ -40,4 +40,4 @@ minimumIdle = 10 # 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count) maximumPoolSize = 10 # 连接只读数据库时配置为true, 保证安全 -readOnly = false \ No newline at end of file +readOnly = false diff --git a/hutool-db/src/test/resources/config/example/db-example-tomcat.setting b/hutool-db/src/test/resources/config/example/db-example-tomcat.setting index 6f8567f24..95c6c6310 100644 --- a/hutool-db/src/test/resources/config/example/db-example-tomcat.setting +++ b/hutool-db/src/test/resources/config/example/db-example-tomcat.setting @@ -48,4 +48,4 @@ testOnBorrow = false # (boolean) 指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串 testOnReturn = false # (boolean) 指明连接是否被空闲连接回收器( 如果有) 进行检验。 如果检测失败, 则连接将被从池中去除。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串 -testWhileIdle = false \ No newline at end of file +testWhileIdle = false diff --git a/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java b/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java index 61307eaa8..641a44615 100755 --- a/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java +++ b/hutool-setting/src/main/java/cn/hutool/setting/SettingLoader.java @@ -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); }