mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-05-09 23:51:34 +08:00
change loader
This commit is contained in:
parent
61ede3182c
commit
25d82a7d1f
@ -3,9 +3,11 @@
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
# 5.4. (2020-09-18)
|
||||
# 5.4.4 (2020-09-19)
|
||||
|
||||
### 新特性
|
||||
* 【core 】 ServiceLoaderUtil改为使用contextClassLoader(pr#183@Gitee)
|
||||
|
||||
### Bug修复
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
@ -1,12 +1,12 @@
|
||||
package cn.hutool.core.util;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
|
||||
/**
|
||||
* SPI机制中的服务加载工具类,流程如下
|
||||
*
|
||||
@ -34,7 +34,7 @@ public class ServiceLoaderUtil {
|
||||
while (iterator.hasNext()) {
|
||||
try {
|
||||
return iterator.next();
|
||||
} catch (ServiceConfigurationError e) {
|
||||
} catch (ServiceConfigurationError ignore) {
|
||||
// ignore
|
||||
}
|
||||
}
|
||||
@ -64,7 +64,7 @@ public class ServiceLoaderUtil {
|
||||
* @return 服务接口实现列表
|
||||
*/
|
||||
public static <T> ServiceLoader<T> load(Class<T> clazz) {
|
||||
return load(clazz, Thread.currentThread().getContextClassLoader());
|
||||
return load(clazz, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -76,7 +76,7 @@ public class ServiceLoaderUtil {
|
||||
* @return 服务接口实现列表
|
||||
*/
|
||||
public static <T> ServiceLoader<T> load(Class<T> clazz, ClassLoader loader) {
|
||||
return ServiceLoader.load(clazz, loader);
|
||||
return ServiceLoader.load(clazz, ObjectUtil.defaultIfNull(loader, ClassLoaderUtil.getClassLoader()));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,6 +101,6 @@ public class ServiceLoaderUtil {
|
||||
* @since 5.4.2
|
||||
*/
|
||||
public static <T> List<T> loadList(Class<T> clazz, ClassLoader loader) {
|
||||
return ListUtil.list(false, load(clazz));
|
||||
return ListUtil.list(false, load(clazz, loader));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user