gu.sql2java.utils.SPIUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sql2java-base Show documentation
Show all versions of sql2java-base Show documentation
sql2java common class package
package gu.sql2java.utils;
import java.util.ServiceLoader;
/**
* @author guyadong
* @since 3.26.2
*
*/
public class SPIUtils {
private SPIUtils() {
}
/**
* 优先调用{@link ServiceLoader#load(Class)},如果返回为空则调用{@link ServiceLoader#load(Class, ClassLoader)}
* @param
* @param service
*/
public static ServiceLoader serviceLoaderOf(Class service){
ServiceLoader loader = ServiceLoader.load(service);
return loader.iterator().hasNext() ? loader : ServiceLoader.load(service,service.getClassLoader());
}
}