getAllPluginId();
/**
* 预加载, 只读取元信息和 load boot class 和配置, 不做 bean 加载.
*/
Plugin preLoad(File file);
/**
* 加载插件
*/
Plugin load(File file) throws Throwable;
/**
* 卸载插件
*/
void unload(String pluginId) throws Exception;
/**
* 获取多个扩展点的插件实例
*/
List
get(String extCode);
/**
* 获取多个扩展点的插件实例
*/
List
get(Class
pClass);
/**
* 获取单个插件实例.
*/
Optional
get(String extCode, String pluginId);
}
```
## SPI 扩展
#### cn.think.in.java.open.exp.client.PluginFilter
可在获取实例过程中过滤`扩展点实现`
```java
public interface PluginFilter {
List> filter(List> list);
@Data
class FModel {
T t;
String pluginId;
public FModel(T t, String pluginId) {
this.t = t;
this.pluginId = pluginId;
}
}
}
```
````java
// 假如实现了 PluginFilter SPI 接口, 可进行自定义过滤
List userServices = expAppContext.get(UserService.class);
// first 第一个就是这个租户优先级最高的.
Optional optional = userServices.stream().findFirst();
````
#### cn.think.in.java.open.exp.client.PluginConfig
插件配置 SPI, 相较于普通的 config api, 会多出一个 pluginId 维度, 方便基线管理各个插件的配置
```java
public interface PluginConfig {
String getProperty(String pluginId, String key, String defaultValue);
}
```
插件获取配置示例代码:
```java
public class Boot extends AbstractBoot {
// 定义配置, key name 和 Default value;
public static ConfigSupport configSupport = new ConfigSupport("bv2", null);
}
public String hello() {
return configSupport.getProperty();
}
```
## 插件核心其他配置
springboot 配置项(-D 或 application.yml 都支持):
```java
plugins_path={springboot 启动时, exp主动加载的插件目录}
plugins_work_dir={exp 的工作目录, 其会将代码解压达成这个目录里,子目录名为插件 id}
plugins_auto_delete_enable={是否自动删除已经存在的 plugin 目录}
plugins_spring_url_replace_enable={插件是否可以覆盖主程序 url, 注意, 目前无法支持多租户级别的覆盖}
exp_object_field_config_json={插件动态增加字段json, json 结构定义见: cn.think.in.java.open.exp.object.field.ext.ExtMetaBean}
```
## 插件配置
1. [pluginMeta.properties](example%2Fexample-plugin-empty%2Fsrc%2Fmain%2Fresources%2FpluginMeta.properties)
```properties
# 插件 boot class
plugin.boot.class=cn.think.in.java.open.exp.example.empty.Boot
# code 名 不能为空
plugin.code=example.plugin.empty
# 描述
plugin.desc=this a plugin a empty demo
# 版本
plugin.version=1.0.0
```
2. [extension.properties](example%2Fexample-plugin-b-v2%2Fsrc%2Fmain%2Fresources%2Fextension.properties)
扩展点映射
```properties
cn.think.in.java.open.exp.adapter.springboot2.example.UserService=\
cn.think.in.java.open.exp.example.b.UserPlugin
```
## License
[Apache 2.0 License.](https://github.com/stateIs0/exp/blob/master/LICENSE)
## Stargazers over time
[](https://starchart.cc/stateIs0/exp)