diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e25de24c..980475f02 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,8 @@ 6. 新增WebSSH 管理功能 7. 【Server】用户新增邮箱和钉钉群webhook 属性 8. 【Server】监控报警通知改为联系人 +9. 【Server】引人netty插件(感谢@夜空中最亮的星) +10. 支持docker 容器运行(感谢@24k) ### 解决BUG、优化功能 diff --git a/modules/common/src/main/java/cn/keepbx/jpom/JpomApplication.java b/modules/common/src/main/java/cn/keepbx/jpom/JpomApplication.java index 2caddbf55..364a3c416 100644 --- a/modules/common/src/main/java/cn/keepbx/jpom/JpomApplication.java +++ b/modules/common/src/main/java/cn/keepbx/jpom/JpomApplication.java @@ -25,11 +25,6 @@ import java.nio.charset.Charset; */ public class JpomApplication extends ApplicationBuilder { - static { - // 初始化插件 - PluginFactory.init(); - } - /** * */ @@ -68,6 +63,8 @@ public class JpomApplication extends ApplicationBuilder { addInterceptor(PluginFeatureInterceptor.class); // addApplicationEventClient(new JpomApplicationEvent()); + // 添加初始化监听 + this.application().addInitializers(new PluginFactory()); } private void checkEvent(String[] args) throws Exception { diff --git a/modules/common/src/main/java/cn/keepbx/plugin/PluginFactory.java b/modules/common/src/main/java/cn/keepbx/plugin/PluginFactory.java index e2194bb5b..9c6194d63 100644 --- a/modules/common/src/main/java/cn/keepbx/plugin/PluginFactory.java +++ b/modules/common/src/main/java/cn/keepbx/plugin/PluginFactory.java @@ -1,5 +1,16 @@ package cn.keepbx.plugin; +import cn.hutool.core.io.FileUtil; +import cn.hutool.core.lang.JarClassLoader; +import cn.hutool.core.util.ClassLoaderUtil; +import cn.hutool.core.util.StrUtil; +import cn.jiangzeyin.common.DefaultSystemLog; +import cn.keepbx.jpom.model.system.JpomManifest; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; + +import java.io.File; +import java.net.URLClassLoader; import java.util.ArrayList; import java.util.List; @@ -9,7 +20,7 @@ import java.util.List; * @author bwcx_jzy * @date 2019/8/13 */ -public class PluginFactory { +public class PluginFactory implements ApplicationContextInitializer { private static final List FEATURE_CALLBACKS = new ArrayList<>(); @@ -29,7 +40,40 @@ public class PluginFactory { /** * 正式环境添加依赖 */ - public static void init() { + private static void init() { + if (JpomManifest.getInstance().isDebug()) { + return; + } + File runPath = JpomManifest.getRunPath().getParentFile(); + File plugin = FileUtil.file(runPath, "plugin"); + if (!plugin.exists() || plugin.isFile()) { + return; + } + File[] files = plugin.listFiles(File::isDirectory); + if (files == null) { + return; + } + for (File file : files) { + File lib = FileUtil.file(file, "lib"); + if (!lib.exists() || lib.isFile()) { + continue; + } + File[] listFiles = lib.listFiles((dir, name) -> StrUtil.endWith(name, ".jar", true)); + if (listFiles == null || listFiles.length <= 0) { + continue; + } + addPlugin(file.getName(), lib); + } + } + private static void addPlugin(String pluginName, File file) { + DefaultSystemLog.LOG().info("加载:{}插件", pluginName); + ClassLoader contextClassLoader = ClassLoaderUtil.getClassLoader(); + JarClassLoader.loadJar((URLClassLoader) contextClassLoader, file); + } + + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + init(); } }