hutool SPI serviceloader 实例
所属分类 hutool
浏览量 147
hutool-all-5.8.28.jar
hutool-all-5.8.28.jar!/META-INF/services/cn.hutool.aop.proxy.ProxyFactory
cn.hutool.aop.proxy.CglibProxyFactory
cn.hutool.aop.proxy.SpringCglibProxyFactory
cn.hutool.aop.proxy.JdkProxyFactory
ProxyFactory pf = ServiceLoaderUtil.loadFirstAvailable(ProxyFactory.class);
import cn.hutool.aop.proxy.ProxyFactory;
import java.util.Iterator;
import java.util.ServiceLoader;
ServiceLoader< ProxyFactory> sl = ServiceLoader.load(ProxyFactory.class);
Iterator< ProxyFactory> it = sl.iterator();
while(it.hasNext()){
try{
System.out.println(it.next().toString());
}catch(Throwable e){
// 注意 不能用 Exception !!!
System.out.println(e);
}
}
ProxyFactory pf = ServiceLoaderUtil.loadFirstAvailable(ProxyFactory.class);
System.out.println("ProxyFactory="+pf.toString());
java.util.ServiceConfigurationError: cn.hutool.aop.proxy.ProxyFactory: Provider cn.hutool.aop.proxy.CglibProxyFactory could not be instantiated
java.util.ServiceConfigurationError: cn.hutool.aop.proxy.ProxyFactory: Provider cn.hutool.aop.proxy.SpringCglibProxyFactory could not be instantiated
cn.hutool.aop.proxy.JdkProxyFactory@610455d6
ProxyFactory=cn.hutool.aop.proxy.JdkProxyFactory@610455d6
java.util.ServiceConfigurationError
public class ServiceConfigurationError extends Error
public class Error extends Throwable
增加依赖
cglib
cglib
3.2.7
cglib/cglib/3.2.7/cglib-3.2.7.jar
CglibProxyFactory 加载成功
cn.hutool.aop.proxy.CglibProxyFactory@63947c6b
java.util.ServiceConfigurationError: cn.hutool.aop.proxy.ProxyFactory: Provider cn.hutool.aop.proxy.SpringCglibProxyFactory could not be instantiated
cn.hutool.aop.proxy.JdkProxyFactory@6ff3c5b5
ProxyFactory=cn.hutool.aop.proxy.CglibProxyFactory@63947c6b
https://hutoolkit.com/docs/aop/proxyutil/
上一篇
下一篇
talib简介
程序员 如何利用 个人网站 自媒体赚钱
springboot3 自动配置文件
hutool 常用方法
hutool使用常见问题
hutool-db hsqldb2 例子