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
|
# 🚀Changelog
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.37(2025-02-18)
|
# 5.8.37(2025-02-24)
|
||||||
|
|
||||||
### 🐣新特性
|
### 🐣新特性
|
||||||
* 【json 】 ObjectMapper删除重复trim(pr#3859@Github)
|
* 【json 】 ObjectMapper删除重复trim(pr#3859@Github)
|
||||||
* 【core 】 `FileWriter`增加方法,可选是否追加换行符(issue#3858@Github)
|
* 【core 】 `FileWriter`增加方法,可选是否追加换行符(issue#3858@Github)
|
||||||
|
|
||||||
### 🐞Bug修复
|
### 🐞Bug修复
|
||||||
|
* 【setting】 修复`SettingLoader`load未抛出异常导致配置文件无法正常遍历的问题(pr#3868@Github)
|
||||||
|
|
||||||
-------------------------------------------------------------------------------------------------------------
|
-------------------------------------------------------------------------------------------------------------
|
||||||
# 5.8.36(2025-02-18)
|
# 5.8.36(2025-02-18)
|
||||||
|
@ -1351,11 +1351,11 @@ public class FileUtil extends PathUtil {
|
|||||||
if (null == classPath) {
|
if (null == classPath) {
|
||||||
// throw new NullPointerException("ClassPath is null !");
|
// throw new NullPointerException("ClassPath is null !");
|
||||||
// 在jar运行模式中,ClassPath有可能获取不到,此时返回原始相对路径(此时获取的文件为相对工作目录)
|
// 在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();
|
||||||
|
}
|
||||||
|
}
|
@ -51,4 +51,4 @@ idleConnectionTestPeriod = 0
|
|||||||
# c3p0全局的PreparedStatements缓存的大小。如果maxStatements与maxStatementsPerConnection均为0,则缓存不生效,只要有一个不为0,则语句的缓存就能生效。如果默认值: 0
|
# c3p0全局的PreparedStatements缓存的大小。如果maxStatements与maxStatementsPerConnection均为0,则缓存不生效,只要有一个不为0,则语句的缓存就能生效。如果默认值: 0
|
||||||
maxStatements = 0
|
maxStatements = 0
|
||||||
# maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。默认值: 0
|
# maxStatementsPerConnection定义了连接池内单个连接所拥有的最大缓存statements数。默认值: 0
|
||||||
maxStatementsPerConnection = 0
|
maxStatementsPerConnection = 0
|
||||||
|
@ -48,4 +48,4 @@ testOnBorrow = false
|
|||||||
# (boolean) 指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
|
# (boolean) 指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
|
||||||
testOnReturn = false
|
testOnReturn = false
|
||||||
# (boolean) 指明连接是否被空闲连接回收器( 如果有) 进行检验。 如果检测失败, 则连接将被从池中去除。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
|
# (boolean) 指明连接是否被空闲连接回收器( 如果有) 进行检验。 如果检测失败, 则连接将被从池中去除。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
|
||||||
testWhileIdle = false
|
testWhileIdle = false
|
||||||
|
@ -52,4 +52,4 @@ connectionInitSqls = SELECT 1
|
|||||||
# 属性类型是字符串,通过别名的方式配置扩展插件, 常用的插件有: 监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall
|
# 属性类型是字符串,通过别名的方式配置扩展插件, 常用的插件有: 监控统计用的filter:stat 日志用的filter:log4j 防御sql注入的filter:wall
|
||||||
filters = stat
|
filters = stat
|
||||||
# 类型是List<com.alibaba.druid.filter.Filter>, 如果同时配置了filters和proxyFilters, 是组合关系,并非替换关系
|
# 类型是List<com.alibaba.druid.filter.Filter>, 如果同时配置了filters和proxyFilters, 是组合关系,并非替换关系
|
||||||
proxyFilters =
|
proxyFilters =
|
||||||
|
@ -40,4 +40,4 @@ minimumIdle = 10
|
|||||||
# 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
|
# 连接池中允许的最大连接数。缺省值:10;推荐的公式:((core_count * 2) + effective_spindle_count)
|
||||||
maximumPoolSize = 10
|
maximumPoolSize = 10
|
||||||
# 连接只读数据库时配置为true, 保证安全
|
# 连接只读数据库时配置为true, 保证安全
|
||||||
readOnly = false
|
readOnly = false
|
||||||
|
@ -48,4 +48,4 @@ testOnBorrow = false
|
|||||||
# (boolean) 指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
|
# (boolean) 指明是否在归还到池中前进行检验 注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
|
||||||
testOnReturn = false
|
testOnReturn = false
|
||||||
# (boolean) 指明连接是否被空闲连接回收器( 如果有) 进行检验。 如果检测失败, 则连接将被从池中去除。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
|
# (boolean) 指明连接是否被空闲连接回收器( 如果有) 进行检验。 如果检测失败, 则连接将被从池中去除。注意: 设置为true 后如果要生效,validationQuery 参数必须设置为非空字符串
|
||||||
testWhileIdle = false
|
testWhileIdle = false
|
||||||
|
@ -2,20 +2,13 @@ package cn.hutool.setting;
|
|||||||
|
|
||||||
import cn.hutool.core.io.FileUtil;
|
import cn.hutool.core.io.FileUtil;
|
||||||
import cn.hutool.core.io.IoUtil;
|
import cn.hutool.core.io.IoUtil;
|
||||||
|
import cn.hutool.core.io.resource.NoResourceException;
|
||||||
import cn.hutool.core.io.resource.Resource;
|
import cn.hutool.core.io.resource.Resource;
|
||||||
import cn.hutool.core.lang.Assert;
|
import cn.hutool.core.lang.Assert;
|
||||||
import cn.hutool.core.util.CharUtil;
|
import cn.hutool.core.util.*;
|
||||||
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.log.Log;
|
import cn.hutool.log.Log;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.*;
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.io.PrintWriter;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashMap;
|
import java.util.LinkedHashMap;
|
||||||
@ -73,19 +66,22 @@ public class SettingLoader {
|
|||||||
*
|
*
|
||||||
* @param resource 配置文件URL
|
* @param resource 配置文件URL
|
||||||
* @return 加载是否成功
|
* @return 加载是否成功
|
||||||
|
* @throws NoResourceException 如果资源不存在,抛出此异常
|
||||||
*/
|
*/
|
||||||
public boolean load(Resource resource) {
|
public boolean load(Resource resource) throws NoResourceException{
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
throw new NullPointerException("Null setting url define!");
|
throw new NullPointerException("Null setting url define!");
|
||||||
}
|
}
|
||||||
log.debug("Load setting file [{}]", resource);
|
|
||||||
InputStream settingStream = null;
|
InputStream settingStream = null;
|
||||||
try {
|
try {
|
||||||
settingStream = resource.getStream();
|
settingStream = resource.getStream();
|
||||||
load(settingStream);
|
load(settingStream);
|
||||||
|
log.debug("Load setting file [{}]", resource);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e, "Load setting error!");
|
if(e instanceof NoResourceException){
|
||||||
return false;
|
throw (NoResourceException)e;
|
||||||
|
}
|
||||||
|
throw new NoResourceException(e);
|
||||||
} finally {
|
} finally {
|
||||||
IoUtil.close(settingStream);
|
IoUtil.close(settingStream);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user