mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix code
This commit is contained in:
parent
656c551068
commit
f504a176e4
@ -278,7 +278,12 @@ public class ResourceUtil {
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取同名的所有资源
|
||||
* 获取同名的所有资源<br>
|
||||
* 资源的加载顺序是:
|
||||
* <ul>
|
||||
* <li>1. 首先在本项目下查找资源文件</li>
|
||||
* <li>2. 按照classpath定义的顺序,去对应路径或jar包下寻找资源文件</li>
|
||||
* </ul>
|
||||
*
|
||||
* @param resource 资源名
|
||||
* @param classLoader {@link ClassLoader},{@code null}表示使用默认的当前上下文ClassLoader
|
||||
@ -330,11 +335,26 @@ public class ResourceUtil {
|
||||
* @param resourceName 资源名,可以是相对classpath的路径,也可以是绝对路径
|
||||
* @param classLoader {@link ClassLoader},{@code null}表示使用默认的当前上下文ClassLoader
|
||||
* @param charset 编码,对XML无效,默认UTF-8
|
||||
* @param isOverride 是否覆盖模式
|
||||
*/
|
||||
public static void loadAllTo(final Properties properties, final String resourceName,
|
||||
final ClassLoader classLoader, final Charset charset) {
|
||||
final ClassLoader classLoader, final Charset charset, final boolean isOverride) {
|
||||
if(isOverride){
|
||||
for (final Resource resource : getResources(resourceName, classLoader)) {
|
||||
loadTo(properties, resource, charset);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 非覆盖模式下,读取配置文件后逐个检查key
|
||||
final Properties tmpProps = new Properties();
|
||||
for (final Resource resource : getResources(resourceName, classLoader)) {
|
||||
loadTo(properties, resource, charset);
|
||||
loadTo(tmpProps, resource, charset);
|
||||
tmpProps.forEach((name, value)->{
|
||||
if(!properties.containsKey(name)){
|
||||
properties.put(name, value);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -98,12 +98,16 @@ public class KVServiceLoader<S> extends AbsServiceLoader<S> {
|
||||
*/
|
||||
@Override
|
||||
public void load() {
|
||||
// 解析同名的所有service资源
|
||||
// 按照资源加载优先级,先加载和解析的资源优先使用,后加载的同名资源丢弃
|
||||
final Properties properties = new Properties();
|
||||
ResourceUtil.loadAllTo(
|
||||
properties,
|
||||
pathPrefix + serviceClass.getName(),
|
||||
classLoader,
|
||||
charset);
|
||||
charset,
|
||||
// 非覆盖模式
|
||||
false);
|
||||
this.serviceProperties = properties;
|
||||
}
|
||||
|
||||
|
@ -100,6 +100,7 @@ public class ListServiceLoader<S> extends AbsServiceLoader<S> {
|
||||
@Override
|
||||
public void load() {
|
||||
// 解析同名的所有service资源
|
||||
// 按照资源加载优先级,先加载和解析的资源优先使用,后加载的同名资源丢弃
|
||||
final MultiResource resources = ResourceUtil.getResources(
|
||||
pathPrefix + serviceClass.getName(),
|
||||
this.classLoader);
|
||||
|
Loading…
x
Reference in New Issue
Block a user