S - 服务类型public class MapServiceLoader<S> extends AbsServiceLoader<S>
Properties加载并存储服务内容类似于:
# 我是注释
service1 = hutool.service.Service1
service2 = hutool.service.Service2
通过调用getService(String)方法,传入等号前的名称,即可获取对应服务。
charset, classLoader, pathPrefix, serviceClass| Constructor and Description |
|---|
MapServiceLoader(String pathPrefix,
Class<S> serviceClass,
ClassLoader classLoader,
Charset charset)
构造
|
| Modifier and Type | Method and Description |
|---|---|
S |
getService(String serviceName)
获取指定名称对应的服务
|
Class<S> |
getServiceClass(String serviceName)
获取指定服务的实现类
|
List<String> |
getServiceNames()
获取服务名称列表
|
Iterator<S> |
iterator() |
void |
load()
加载或重新加载全部服务
|
static <S> MapServiceLoader<S> |
of(Class<S> serviceClass)
构建KVServiceLoader
|
static <S> MapServiceLoader<S> |
of(Class<S> serviceClass,
ClassLoader classLoader)
构建KVServiceLoader
|
static <S> MapServiceLoader<S> |
of(String pathPrefix,
Class<S> serviceClass,
ClassLoader classLoader)
构建KVServiceLoader
|
int |
size()
服务总数
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitforEach, spliteratorpublic MapServiceLoader(String pathPrefix, Class<S> serviceClass, ClassLoader classLoader, Charset charset)
pathPrefix - 路径前缀serviceClass - 服务名称classLoader - 自定义类加载器, null表示使用默认当前的类加载器charset - 编码,默认UTF-8public static <S> MapServiceLoader<S> of(Class<S> serviceClass)
S - 服务类型serviceClass - 服务名称public static <S> MapServiceLoader<S> of(Class<S> serviceClass, ClassLoader classLoader)
S - 服务类型serviceClass - 服务名称classLoader - 自定义类加载器, null表示使用默认当前的类加载器public static <S> MapServiceLoader<S> of(String pathPrefix, Class<S> serviceClass, ClassLoader classLoader)
S - 服务类型pathPrefix - 路径前缀serviceClass - 服务名称classLoader - 自定义类加载器, null表示使用默认当前的类加载器public void load()
public int size()
ServiceLoaderpublic List<String> getServiceNames()
ServiceLoaderpublic Class<S> getServiceClass(String serviceName)
ServiceLoaderserviceName - 服务名称public S getService(String serviceName)
ServiceLoaderserviceName - 服务名称Copyright © 2025. All rights reserved.