增加插件模式
This commit is contained in:
41
src/main/java/com/jsh/erp/config/ExamplePluginListener.java
Normal file
41
src/main/java/com/jsh/erp/config/ExamplePluginListener.java
Normal file
@@ -0,0 +1,41 @@
|
||||
package com.jsh.erp.config;
|
||||
|
||||
import com.gitee.starblues.integration.application.PluginApplication;
|
||||
import com.gitee.starblues.integration.listener.PluginListener;
|
||||
import com.gitee.starblues.integration.user.PluginUser;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
||||
/**
|
||||
* 插件监听者
|
||||
*
|
||||
* @author jishenghua
|
||||
* @version 1.0
|
||||
*/
|
||||
public class ExamplePluginListener implements PluginListener {
|
||||
|
||||
private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
||||
|
||||
private final PluginUser pluginUser;
|
||||
|
||||
public ExamplePluginListener(PluginApplication pluginApplication){
|
||||
this.pluginUser = pluginApplication.getPluginUser();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void registry(String pluginId) {
|
||||
logger.info("Listener: registry pluginId {}", pluginId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unRegistry(String pluginId) {
|
||||
logger.info("Listener: unRegistry pluginId {}", pluginId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(String pluginId, Throwable throwable) {
|
||||
|
||||
}
|
||||
}
|
||||
30
src/main/java/com/jsh/erp/config/PluginBeanConfig.java
Normal file
30
src/main/java/com/jsh/erp/config/PluginBeanConfig.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.jsh.erp.config;
|
||||
|
||||
import com.gitee.starblues.integration.application.AutoPluginApplication;
|
||||
import com.gitee.starblues.integration.application.PluginApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* 插件集成配置
|
||||
*
|
||||
* @author jishenghua
|
||||
* @version 1.0
|
||||
*/
|
||||
@Configuration
|
||||
public class PluginBeanConfig {
|
||||
|
||||
|
||||
/**
|
||||
* 定义插件应用。使用可以注入它操作插件。
|
||||
* @return PluginApplication
|
||||
*/
|
||||
@Bean
|
||||
public PluginApplication pluginApplication(PluginListener pluginListener){
|
||||
AutoPluginApplication autoPluginApplication = new AutoPluginApplication();
|
||||
autoPluginApplication.setPluginInitializerListener(pluginListener);
|
||||
autoPluginApplication.addListener(ExamplePluginListener.class);
|
||||
return autoPluginApplication;
|
||||
}
|
||||
|
||||
}
|
||||
130
src/main/java/com/jsh/erp/config/PluginConfiguration.java
Normal file
130
src/main/java/com/jsh/erp/config/PluginConfiguration.java
Normal file
@@ -0,0 +1,130 @@
|
||||
package com.jsh.erp.config;
|
||||
|
||||
import com.gitee.starblues.integration.DefaultIntegrationConfiguration;
|
||||
import org.pf4j.RuntimeMode;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
|
||||
/**
|
||||
* 插件集成配置
|
||||
*
|
||||
* @author jishenghua
|
||||
* @version 1.0
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix = "plugin")
|
||||
public class PluginConfiguration extends DefaultIntegrationConfiguration {
|
||||
|
||||
/**
|
||||
* 运行模式
|
||||
* 开发环境: development、dev
|
||||
* 生产/部署 环境: deployment、prod
|
||||
*/
|
||||
@Value("${runMode:dev}")
|
||||
private String runMode;
|
||||
|
||||
/**
|
||||
* 插件的路径
|
||||
*/
|
||||
@Value("${pluginPath:plugins}")
|
||||
private String pluginPath;
|
||||
|
||||
/**
|
||||
* 插件文件的路径
|
||||
*/
|
||||
@Value("${pluginConfigFilePath:pluginConfigs}")
|
||||
private String pluginConfigFilePath;
|
||||
|
||||
|
||||
@Override
|
||||
public RuntimeMode environment() {
|
||||
return RuntimeMode.byName(runMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pluginPath() {
|
||||
return pluginPath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String pluginConfigFilePath() {
|
||||
return pluginConfigFilePath;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写上传插件包的临时存储路径。只适用于生产环境
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public String uploadTempPath() {
|
||||
return "temp";
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写插件备份路径。只适用于生产环境
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public String backupPath() {
|
||||
return "backupPlugin";
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写插件RestController请求的路径前缀
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public String pluginRestControllerPathPrefix() {
|
||||
return "/api/plugins";
|
||||
}
|
||||
|
||||
/**
|
||||
* 重写是否启用插件id作为RestController请求的路径前缀。
|
||||
* 启动则插件id会作为二级路径前缀。即: /api/plugins/pluginId/**
|
||||
* @return String
|
||||
*/
|
||||
@Override
|
||||
public boolean enablePluginIdRestControllerPathPrefix() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public String getRunMode() {
|
||||
return runMode;
|
||||
}
|
||||
|
||||
public void setRunMode(String runMode) {
|
||||
this.runMode = runMode;
|
||||
}
|
||||
|
||||
|
||||
public String getPluginPath() {
|
||||
return pluginPath;
|
||||
}
|
||||
|
||||
public void setPluginPath(String pluginPath) {
|
||||
this.pluginPath = pluginPath;
|
||||
}
|
||||
|
||||
public String getPluginConfigFilePath() {
|
||||
return pluginConfigFilePath;
|
||||
}
|
||||
|
||||
public void setPluginConfigFilePath(String pluginConfigFilePath) {
|
||||
this.pluginConfigFilePath = pluginConfigFilePath;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PluginArgConfiguration{" +
|
||||
"runMode='" + runMode + '\'' +
|
||||
", pluginPath='" + pluginPath + '\'' +
|
||||
", pluginConfigFilePath='" + pluginConfigFilePath + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
28
src/main/java/com/jsh/erp/config/PluginListener.java
Normal file
28
src/main/java/com/jsh/erp/config/PluginListener.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.jsh.erp.config;
|
||||
|
||||
import com.gitee.starblues.integration.listener.PluginInitializerListener;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 插件监听者
|
||||
*
|
||||
* @author jishenghua
|
||||
* @version 1.0
|
||||
*/
|
||||
@Component
|
||||
public class PluginListener implements PluginInitializerListener {
|
||||
@Override
|
||||
public void before() {
|
||||
System.out.println("before");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void complete() {
|
||||
System.out.println("complete");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void failure(Throwable throwable) {
|
||||
System.out.println("failure:"+throwable.getMessage());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user