diff --git a/example/basic-example/basic-example-main/pom.xml b/example/basic-example/basic-example-main/pom.xml index 24b074301b48e286f3698de6578d3051139424b9..eaf35d85918457f16c144b1291990ce5e838f994 100644 --- a/example/basic-example/basic-example-main/pom.xml +++ b/example/basic-example/basic-example-main/pom.xml @@ -13,14 +13,14 @@ com.gitee.starblues basic-example-main - 2.4.1-RELEASE + 2.4.2-RELEASE jar 2.7.0 2.3.2 1.6 - 2.4.1-RELEASE + 2.4.2-RELEASE diff --git a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/PluginBeanConfig.java b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/PluginBeanConfig.java index d792e0298c3591a0709a105aa6e6f975b152cd37..0deb6fa684340d138c5d11944014658fc3981e13 100644 --- a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/PluginBeanConfig.java +++ b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/PluginBeanConfig.java @@ -3,12 +3,6 @@ package com.basic.example.main.config; import com.gitee.starblues.extension.support.SpringDocControllerProcessor; import com.gitee.starblues.integration.application.PluginApplication; import com.gitee.starblues.integration.application.AutoPluginApplication; -import io.swagger.v3.oas.models.Components; -import io.swagger.v3.oas.models.OpenAPI; -import org.quartz.SchedulerFactory; -import org.springdoc.core.GroupedOpenApi; -import org.springdoc.core.SpringDocUtils; -import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -29,8 +23,7 @@ public class PluginBeanConfig { * @return PluginApplication */ @Bean - public PluginApplication pluginApplication(PluginListener pluginListener, - SchedulerFactory schedulerFactory){ + public PluginApplication pluginApplication(PluginListener pluginListener){ AutoPluginApplication autoPluginApplication = new AutoPluginApplication(); autoPluginApplication.setPluginInitializerListener(pluginListener); autoPluginApplication.addListener(ExamplePluginListener.class); diff --git a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/PluginConfiguration.java b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/PluginConfiguration.java index 3eb0e2870092c08978abeb467094eef538789222..026b7b8250ae40d8fee8e9f9b3b471ef99d7904e 100644 --- a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/PluginConfiguration.java +++ b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/PluginConfiguration.java @@ -105,6 +105,11 @@ public class PluginConfiguration extends DefaultIntegrationConfiguration { return "1.2.6"; } + @Override + public boolean enableWebSocket() { + return true; + } + public String getRunMode() { return runMode; } diff --git a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/WebSocketConfig b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/WebSocketConfig.java similarity index 89% rename from example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/WebSocketConfig rename to example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/WebSocketConfig.java index 8bb35fe0837ebfbe1c54940254c7d239e6e7cab5..a08ce81ef4efea1d64f72be933943ccd622d31f5 100644 --- a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/WebSocketConfig +++ b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/config/WebSocketConfig.java @@ -1,15 +1,19 @@ -package com.basic.example.main.config; - -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.web.socket.server.standard.ServerEndpointExporter; - -@Configuration -public class WebSocketConfig { - - @Bean - public ServerEndpointExporter serverEndpointExporter() { - return new ServerEndpointExporter(); - } - -} +package com.basic.example.main.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.web.socket.server.standard.ServerEndpointExporter; + +/** + * @author starBlues + * @version 1.0 + */ +@Configuration +public class WebSocketConfig { + + @Bean + public ServerEndpointExporter serverEndpointExporter() { + return new ServerEndpointExporter(); + } + +} diff --git a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/rest/HelloResource.java b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/rest/HelloResource.java index beefe2c27d4ed6d1b18d0f265907443e139a43f8..8874703260d6d2bfa1fcdbc8835b6fa796a67937 100644 --- a/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/rest/HelloResource.java +++ b/example/basic-example/basic-example-main/src/main/java/com/basic/example/main/rest/HelloResource.java @@ -1,7 +1,6 @@ package com.basic.example.main.rest; import com.basic.example.main.plugin.Hello; -import com.gitee.starblues.integration.application.PluginApplication; import com.gitee.starblues.integration.user.PluginUser; import com.basic.example.main.plugin.ConsoleName; import com.basic.example.main.plugin.ConsoleNameFactory; diff --git a/example/basic-example/basic-example-runner/pom.xml b/example/basic-example/basic-example-runner/pom.xml index fd6f04a7f59b294e60bb6c26e1736ebd6264b7e9..ada91f7f819eca9dea6df431671b401bcbd76509 100644 --- a/example/basic-example/basic-example-runner/pom.xml +++ b/example/basic-example/basic-example-runner/pom.xml @@ -14,7 +14,7 @@ com.gitee.starblues basic-example-runner - 2.4.1-RELEASE + 2.4.2-RELEASE pom diff --git a/example/basic-example/plugins/basic-example-plugin1/pom.xml b/example/basic-example/plugins/basic-example-plugin1/pom.xml index 59e5eebe9ac753ee55cc25a74c535e97c0f83f42..96e72fd56d842b5f15e0a80c5188e43ea91b09f9 100644 --- a/example/basic-example/plugins/basic-example-plugin1/pom.xml +++ b/example/basic-example/plugins/basic-example-plugin1/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues basic-example-plugin-parent - 2.4.1-RELEASE + 2.4.2-RELEASE ../pom.xml basic-example-plugin1 - 2.4.1-RELEASE + 2.4.2-RELEASE jar diff --git a/example/basic-example/plugins/basic-example-plugin1/src/main/java/com/basic/example/plugin1/config/ConfigBean.java b/example/basic-example/plugins/basic-example-plugin1/src/main/java/com/basic/example/plugin1/config/ConfigBean.java index 23d56b9d0ba29e8596beea2b3c8ff0615d05b0c9..c997edccfcdd67a585eaf4fa84a80e172f4a4ac2 100644 --- a/example/basic-example/plugins/basic-example-plugin1/src/main/java/com/basic/example/plugin1/config/ConfigBean.java +++ b/example/basic-example/plugins/basic-example-plugin1/src/main/java/com/basic/example/plugin1/config/ConfigBean.java @@ -2,9 +2,12 @@ package com.basic.example.plugin1.config; import com.basic.example.main.config.PluginConfiguration; import com.gitee.starblues.realize.PluginUtils; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import javax.annotation.Resource; + /** * @author starBlues * @version 1.0 diff --git a/example/basic-example/plugins/basic-example-plugin1/src/main/resources/plugin.properties b/example/basic-example/plugins/basic-example-plugin1/src/main/resources/plugin.properties index d456f7e6919ccad159c49b340ce54f35263278e7..a6f0abe0cad284dd2baf79e17e9417bc44c9fb90 100644 --- a/example/basic-example/plugins/basic-example-plugin1/src/main/resources/plugin.properties +++ b/example/basic-example/plugins/basic-example-plugin1/src/main/resources/plugin.properties @@ -1,5 +1,5 @@ plugin.id=basic-example-plugin1 plugin.class=com.basic.example.plugin1.DefinePlugin -plugin.version=2.4.1-RELEASE +plugin.version=2.4.2-RELEASE plugin.provider=StarBlues plugin.requires=1.2.6 \ No newline at end of file diff --git a/example/basic-example/plugins/basic-example-plugin2/pom.xml b/example/basic-example/plugins/basic-example-plugin2/pom.xml index 1c77458d169ba5206c0396351a128b70d339c799..e062aca4d17fa9fdbf5d1913776edfd5ef3664c6 100644 --- a/example/basic-example/plugins/basic-example-plugin2/pom.xml +++ b/example/basic-example/plugins/basic-example-plugin2/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues basic-example-plugin-parent - 2.4.1-RELEASE + 2.4.2-RELEASE ../pom.xml basic-example-plugin2 - 2.4.1-RELEASE + 2.4.2-RELEASE jar diff --git a/example/basic-example/plugins/basic-example-plugin2/src/main/resources/plugin.properties b/example/basic-example/plugins/basic-example-plugin2/src/main/resources/plugin.properties index 7ad556ee8bba1a0ea6c4104dec46c6d13f0e6363..872974ae3d6c187982b4ccd5da5bd3450bc03921 100644 --- a/example/basic-example/plugins/basic-example-plugin2/src/main/resources/plugin.properties +++ b/example/basic-example/plugins/basic-example-plugin2/src/main/resources/plugin.properties @@ -1,4 +1,4 @@ plugin.id=basic-example-plugin2 plugin.class=com.basic.example.plugin2.DefinePlugin -plugin.version=2.4.1-RELEASE +plugin.version=2.4.2-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/basic-example/plugins/basic-example-plugin3/pom.xml b/example/basic-example/plugins/basic-example-plugin3/pom.xml index c856c3d070759070b7559a7d6eecfc45350c4e1a..68ef69fc3abfa3debbceb4ef8ff202788e0dcf8b 100644 --- a/example/basic-example/plugins/basic-example-plugin3/pom.xml +++ b/example/basic-example/plugins/basic-example-plugin3/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues basic-example-plugin-parent - 2.4.1-RELEASE + 2.4.2-RELEASE ../pom.xml basic-example-plugin3 - 2.4.1-RELEASE + 2.4.2-RELEASE jar diff --git a/example/basic-example/plugins/basic-example-plugin3/src/main/java/com/basic/example/plugin3/DefinePlugin.java b/example/basic-example/plugins/basic-example-plugin3/src/main/java/com/basic/example/plugin3/DefinePlugin.java index 5017cb5f7f29bba3e5d42d36fa5b7a7c4ec92975..6d0b9bddc5b8c38b82dd095c839f7ee648f1ccfb 100644 --- a/example/basic-example/plugins/basic-example-plugin3/src/main/java/com/basic/example/plugin3/DefinePlugin.java +++ b/example/basic-example/plugins/basic-example-plugin3/src/main/java/com/basic/example/plugin3/DefinePlugin.java @@ -5,7 +5,7 @@ import org.pf4j.PluginWrapper; /** * 插件定义类 - * + * websocket 测试网站:http://coolaf.com/tool/chattest * @author starBlues * @version 1.0 */ diff --git a/example/basic-example/plugins/basic-example-plugin3/src/main/resources/plugin.properties b/example/basic-example/plugins/basic-example-plugin3/src/main/resources/plugin.properties index f35c749456ea086869d5fbb2a5269d53272b57aa..403655e2af015cbc433c37bcecd48f5a0f8a238c 100644 --- a/example/basic-example/plugins/basic-example-plugin3/src/main/resources/plugin.properties +++ b/example/basic-example/plugins/basic-example-plugin3/src/main/resources/plugin.properties @@ -1,4 +1,4 @@ plugin.id=basic-example-plugin3 plugin.class=com.basic.example.plugin3.DefinePlugin -plugin.version=2.4.1-RELEASE +plugin.version=2.4.2-RELEASE plugin.provider=sousouki \ No newline at end of file diff --git a/example/basic-example/plugins/pom.xml b/example/basic-example/plugins/pom.xml index e22a0b877c175edcb63f551626e5811fbb850cfe..b726741addb1cbe2ef7aa216656a05ec26f748a0 100644 --- a/example/basic-example/plugins/pom.xml +++ b/example/basic-example/plugins/pom.xml @@ -7,7 +7,7 @@ com.gitee.starblues basic-example-plugin-parent - 2.4.1-RELEASE + 2.4.2-RELEASE pom diff --git a/example/basic-example/pom.xml b/example/basic-example/pom.xml index 9e2cbe0c5f5fb3cb093252101bd8aed203b3ca88..7c64445459e6419050ff5ec9134b0e6eaa199fe8 100644 --- a/example/basic-example/pom.xml +++ b/example/basic-example/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues basic-example - 2.4.1-RELEASE + 2.4.2-RELEASE pom 基本案例 diff --git a/example/integration-mybatis/integration-mybatis-main/pom.xml b/example/integration-mybatis/integration-mybatis-main/pom.xml index c9aeda2470294efa15c0d8366e264a6b50f67e81..bde1828c08c701d2747571d8dc642c0bdcb112b2 100644 --- a/example/integration-mybatis/integration-mybatis-main/pom.xml +++ b/example/integration-mybatis/integration-mybatis-main/pom.xml @@ -14,14 +14,14 @@ com.gitee.starblues integration-mybatis-main - 2.4.1-RELEASE + 2.4.2-RELEASE jar 主程序模块 - 2.4.1-RELEASE - 2.4.1-RELEASE - 2.4.1-RELEASE + 2.4.2-RELEASE + 2.4.2-RELEASE + 2.4.2-RELEASE 2.0.1 2.7.0 1.6 diff --git a/example/integration-mybatis/integration-mybatis-main/src/main/java/com/mybatis/main/config/PluginBeanConfig.java b/example/integration-mybatis/integration-mybatis-main/src/main/java/com/mybatis/main/config/PluginBeanConfig.java index 1c0b551965ea0e8c1ec6fded3e556be460b71bec..2ac9e9bb7645836ba0f83c10d42fc1aa4d5ea5d0 100644 --- a/example/integration-mybatis/integration-mybatis-main/src/main/java/com/mybatis/main/config/PluginBeanConfig.java +++ b/example/integration-mybatis/integration-mybatis-main/src/main/java/com/mybatis/main/config/PluginBeanConfig.java @@ -78,7 +78,8 @@ public class PluginBeanConfig { SpringBootMybatisExtension.Type.MYBATIS )); // 新增静态资源扩展 - StaticResourceExtension staticResourceExtension = new StaticResourceExtension(); + StaticResourceExtension staticResourceExtension = new StaticResourceExtension( + StaticResourceExtension.Include.THYMELEAF); staticResourceExtension.setPathPrefix("static"); staticResourceExtension.setCacheControl(CacheControl.maxAge(1, TimeUnit.HOURS).cachePublic()); pluginApplication.addExtension(staticResourceExtension); diff --git a/example/integration-mybatis/integration-mybatis-plugin-parent/pom.xml b/example/integration-mybatis/integration-mybatis-plugin-parent/pom.xml index e4cc482b0df1f13dc7732a4607094f3f27e1426a..b46cd85ffee3018b524faf3f2da0b23a6154b318 100644 --- a/example/integration-mybatis/integration-mybatis-plugin-parent/pom.xml +++ b/example/integration-mybatis/integration-mybatis-plugin-parent/pom.xml @@ -7,7 +7,7 @@ com.gitee.starblues integration-mybatis-plugin-parent - 2.4.1-RELEASE + 2.4.2-RELEASE pom diff --git a/example/integration-mybatis/integration-mybatis-runner/pom.xml b/example/integration-mybatis/integration-mybatis-runner/pom.xml index 71646f7ee37c7dee672a2d411e4b590c1259faca..3293e338ee99f265724e01fbe4b9b866a9a42719 100644 --- a/example/integration-mybatis/integration-mybatis-runner/pom.xml +++ b/example/integration-mybatis/integration-mybatis-runner/pom.xml @@ -14,7 +14,7 @@ com.gitee.starblues integration-mybatis-runner - 2.4.1-RELEASE + 2.4.2-RELEASE jar 启动程序模块。将启动类配置到该模块下 diff --git a/example/integration-mybatis/package.bat b/example/integration-mybatis/package.bat index c29ee716ed40bc76ff1fae9c9178a79346b55510..937e731f047d9e7bb0664920210dc552e15b11e3 100644 --- a/example/integration-mybatis/package.bat +++ b/example/integration-mybatis/package.bat @@ -13,7 +13,7 @@ mkdir dist\pluginConfig REM copy main program and config -xcopy integration-mybatis-main\target\*-exec.jar dist /s /i +xcopy integration-mybatis-main\target\*-RELEASE.jar dist /s /i xcopy integration-mybatis-main\src\main\resources\application-prod.yml dist /s REM copy plugin and config @@ -26,6 +26,6 @@ xcopy plugins\integration-mybatis-plugin2\src\main\resources\plugin2.yml dist\pl cd dist REM run main -rename *-exec.jar integration-mybatis-start.jar +rename *-RELEASE.jar integration-mybatis-start.jar rename application-prod.yml application.yml java -jar integration-mybatis-start.jar --spring.config.location=application.yml diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml b/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml index 5483da32d27b51998341b6c3da936c56d79bf52c..049828c8d4f0859377ad48f5bbf08159599c8957 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin1/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues integration-mybatis-plugin-parent - 2.4.1-RELEASE + 2.4.2-RELEASE ../../integration-mybatis-plugin-parent/pom.xml integration-mybatis-plugin1 - 2.4.1-RELEASE + 2.4.2-RELEASE jar diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin1/src/main/java/com/mybatis/plugin1/MybatisConfig.java b/example/integration-mybatis/plugins/integration-mybatis-plugin1/src/main/java/com/mybatis/plugin1/MybatisConfig.java index fba3cfc0be6584d0f3b9b0788ed0b6265184b230..0a51343381d03682b33a738eee57555671f2fff2 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin1/src/main/java/com/mybatis/plugin1/MybatisConfig.java +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin1/src/main/java/com/mybatis/plugin1/MybatisConfig.java @@ -2,6 +2,11 @@ package com.mybatis.plugin1; import com.gitee.starblues.annotation.ConfigDefinition; import com.gitee.starblues.extension.mybatis.SpringBootMybatisConfig; +import com.gitee.starblues.integration.operator.module.PluginInfo; +import com.gitee.starblues.realize.ConfigDefinitionTip; +import com.mybatis.main.config.PluginBeanConfig; +import com.mybatis.plugin1.config.Plugin1Config; +import org.springframework.context.ApplicationContext; import org.springframework.stereotype.Component; import java.util.HashSet; @@ -15,8 +20,20 @@ import java.util.Set; @ConfigDefinition public class MybatisConfig implements SpringBootMybatisConfig { + private ConfigDefinitionTip configDefinitionTip; + @Override public Set entityPackage() { + // 测试 configDefinitionTip 的使用 +// PluginInfo currentPluginInfo = configDefinitionTip.getCurrentPluginInfo(); +// System.out.println("MybatisConfig=" + currentPluginInfo); +// Plugin1Config plugin1Config = configDefinitionTip.getOtherConfigDefinition(Plugin1Config.class); +// System.out.println("plugin1Config=" + plugin1Config); +// ApplicationContext mainApplication = configDefinitionTip.getMainApplication(); +// PluginBeanConfig bean = mainApplication.getBean(PluginBeanConfig.class); +// System.out.println("PluginBeanConfig" + bean); + + Set typeAliasesPackage = new HashSet<>(); typeAliasesPackage.add("com.mybatis.plugin1.entity"); return typeAliasesPackage; diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin1/src/main/resources/plugin.properties b/example/integration-mybatis/plugins/integration-mybatis-plugin1/src/main/resources/plugin.properties index 1d2b72d5fa7b9f37b6db37d800e9735d039c3451..76260415a95784e0fd9f492e879eda055535d781 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin1/src/main/resources/plugin.properties +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin1/src/main/resources/plugin.properties @@ -1,4 +1,4 @@ plugin.id=integration-mybatis-plugin1 plugin.class=com.mybatis.plugin1.ExamplePlugin1 -plugin.version=2.4.1-RELEASE +plugin.version=2.4.2-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin2/plugin.properties b/example/integration-mybatis/plugins/integration-mybatis-plugin2/plugin.properties index 72c1ab5282b7bc0c1a55a50cfe22bc2287e4a979..5c9d9ff3ccc5f30397e0df16fef7c668a57fd026 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin2/plugin.properties +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin2/plugin.properties @@ -1,4 +1,4 @@ plugin.id=integration-mybatis-plugin2 plugin.class=com.mybatis.plugin2.ExamplePlugin2 -plugin.version=2.4.1-RELEASE +plugin.version=2.4.2-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/integration-mybatis/plugins/integration-mybatis-plugin2/pom.xml b/example/integration-mybatis/plugins/integration-mybatis-plugin2/pom.xml index 688e2464465bbe59a27c5e64bba21d31bd55ca0d..bf03e5f9f40f802ce987fae5d6a3b05bab5ac370 100644 --- a/example/integration-mybatis/plugins/integration-mybatis-plugin2/pom.xml +++ b/example/integration-mybatis/plugins/integration-mybatis-plugin2/pom.xml @@ -8,12 +8,12 @@ com.gitee.starblues integration-mybatis-plugin-parent - 2.4.1-RELEASE + 2.4.2-RELEASE ../../integration-mybatis-plugin-parent/pom.xml integration-mybatis-plugin2 - 2.4.1-RELEASE + 2.4.2-RELEASE jar diff --git a/example/integration-mybatis/pom.xml b/example/integration-mybatis/pom.xml index 271a5eac9c64d3594cc98e66cd791a802b4a7ccf..c82c1ae6f2fb26df7d56620e81025a43b2e41531 100644 --- a/example/integration-mybatis/pom.xml +++ b/example/integration-mybatis/pom.xml @@ -7,7 +7,7 @@ com.gitee.starblues integration-mybatis - 2.4.1-RELEASE + 2.4.2-RELEASE pom 集成mybatis案例 diff --git a/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml b/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml index dee453b9b2cdeef60138e43370c8e9e046aea800..a8300eff340261450cb5f796fb3b8c8c6256c809 100644 --- a/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml +++ b/example/integration-mybatisplus/integration-mybatisplus-main/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues - 2.4.1-RELEASE + 2.4.2-RELEASE integration-mybatisplus-main jar 集成mybatis-plus 案例--主程序 @@ -25,10 +25,10 @@ 3.7.0 2.0.1 - 3.2.0 + 3.4.1 - 2.4.1-RELEASE - 2.4.1-RELEASE + 2.4.2-RELEASE + 2.4.2-RELEASE 2.7.0 1.6 @@ -72,12 +72,6 @@ ${mybatis-plus-boot-starter.version} - - org.mybatis.spring.boot - mybatis-spring-boot-starter - ${mybatis-spring-boot-starter.version} - - io.springfox springfox-swagger2 diff --git a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/plugin.properties b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/plugin.properties index 767beb9c203da3cd261dd6b88934313e7ea3c37a..1af73e00ec3962ecfbac656905eb9213b6a5c0c2 100644 --- a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/plugin.properties +++ b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/plugin.properties @@ -1,4 +1,4 @@ plugin.id=integration-mybatisplus-plugin plugin.class=com.mybatisplus.plugin.MybatisPlusPlugin -plugin.version=2.4.1-RELEASE +plugin.version=2.4.2-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/pom.xml b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/pom.xml index 6988f1557aad2bf9fab7b35462a8b7a6523ed1e3..943da61420066e4ffcc7a5202f216180043346c2 100644 --- a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/pom.xml +++ b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues integration-mybatisplus-plugin - 2.4.1-RELEASE + 2.4.2-RELEASE jar diff --git a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/src/main/java/com/mybatisplus/plugin/MybatisPlusConfig2.java b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/src/main/java/com/mybatisplus/plugin/MybatisPlusConfig2.java index df5b71b7c7d11428f23b94808b9e9b2458b597ae..f84c8d17cbd6d5201762257c897b4079ef78ecb6 100644 --- a/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/src/main/java/com/mybatisplus/plugin/MybatisPlusConfig2.java +++ b/example/integration-mybatisplus/plugins/integration-mybatisplus-plugin/src/main/java/com/mybatisplus/plugin/MybatisPlusConfig2.java @@ -12,7 +12,7 @@ import java.util.Set; * @version 1.0 * @since 2020-12-14 */ -@ConfigDefinition("") +@ConfigDefinition() public class MybatisPlusConfig2 implements SpringBootMybatisPlusConfig { @Override public Set entityPackage() { diff --git a/example/integration-mybatisplus/pom.xml b/example/integration-mybatisplus/pom.xml index 886c739eca96678aea6c3f679da359563537570b..3119395ad449a7a9cbe2152b374b8bb0c2be324d 100644 --- a/example/integration-mybatisplus/pom.xml +++ b/example/integration-mybatisplus/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues integration-mybatisplus - 2.4.1-RELEASE + 2.4.2-RELEASE pom 集成mybatis-plus案例 diff --git a/example/integration-tkmybatis/integration-tkmybatis-main/pom.xml b/example/integration-tkmybatis/integration-tkmybatis-main/pom.xml index 8746af465a413b5fdff5209b9d371ae4414938a9..be29244b086b0b65696a40e905927f8a505113df 100644 --- a/example/integration-tkmybatis/integration-tkmybatis-main/pom.xml +++ b/example/integration-tkmybatis/integration-tkmybatis-main/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues - 2.4.1-RELEASE + 2.4.2-RELEASE integration-tkmybatis-main jar 集成mybatis-plus 案例--主程序 diff --git a/example/integration-tkmybatis/plugins/integration-tkmybatis-plugin/plugin.properties b/example/integration-tkmybatis/plugins/integration-tkmybatis-plugin/plugin.properties index 01d0a2e675b98466e205e31197e633736fa938b7..55b6531e618e123c4f7f1999bea6540c0a921925 100644 --- a/example/integration-tkmybatis/plugins/integration-tkmybatis-plugin/plugin.properties +++ b/example/integration-tkmybatis/plugins/integration-tkmybatis-plugin/plugin.properties @@ -1,4 +1,4 @@ plugin.id=integration-tkmybatis-plugin plugin.class=com.tkmybatis.plugin.TkMybatisPlugin -plugin.version=2.4.1-RELEASE +plugin.version=2.4.2-RELEASE plugin.provider=StarBlues \ No newline at end of file diff --git a/example/integration-tkmybatis/plugins/integration-tkmybatis-plugin/pom.xml b/example/integration-tkmybatis/plugins/integration-tkmybatis-plugin/pom.xml index 678e485eca031adf82042043fc4ef67d6387c0af..b4877661ec5e1d3fa14ab5538f0231a3994f9753 100644 --- a/example/integration-tkmybatis/plugins/integration-tkmybatis-plugin/pom.xml +++ b/example/integration-tkmybatis/plugins/integration-tkmybatis-plugin/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues integration-tkmybatis-plugin - 2.4.1-RELEASE + 2.4.2-RELEASE jar diff --git a/example/integration-tkmybatis/pom.xml b/example/integration-tkmybatis/pom.xml index 81b2604c5f7ae4652a26cb5b0274d73cfd73b63b..e48c1f7cddbfb896fcf7e54a8c0e30b7ef32d40f 100644 --- a/example/integration-tkmybatis/pom.xml +++ b/example/integration-tkmybatis/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues integration-tkmybatis - 2.4.1-RELEASE + 2.4.2-RELEASE pom 集成mybatis-plus案例 diff --git a/example/pom.xml b/example/pom.xml index 3d16ee68faca35fa5c2e48692a5eced820071c8e..f192a2684053ca4445252be2002751be8564c083 100644 --- a/example/pom.xml +++ b/example/pom.xml @@ -6,7 +6,7 @@ com.gitee.starblues springboot-plugin-framework-example - 2.4.1-RELEASE + 2.4.2-RELEASE pom diff --git a/pom.xml b/pom.xml index 842d5dca36e231a6b1ec17ca89f6bac49fd9a1a0..2efd6ac106dfe1aa350fcee0f27a85e2ba0f7019 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.gitee.starblues springboot-plugin-framework-parent pom - 2.4.1-RELEASE + 2.4.2-RELEASE spring boot 插件开发集成包 diff --git a/springboot-plugin-framework-extension/pom.xml b/springboot-plugin-framework-extension/pom.xml index 5a6ae27d377e51ac78f2a97ae91bace96f4a1bb8..55ce429ed22c68dc62915575b71577ff09d65270 100644 --- a/springboot-plugin-framework-extension/pom.xml +++ b/springboot-plugin-framework-extension/pom.xml @@ -9,7 +9,7 @@ com.gitee.starblues springboot-plugin-framework-extension pom - 2.4.1-RELEASE + 2.4.2-RELEASE spring boot 插件式开发集成包--扩展模块 diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/README.md b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/README.md index ec5f526caf1d9317957fc5f52ff60729fe42c280..5bfc4fb383df33b787d24919bdeebed1c63587f5 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/README.md +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/README.md @@ -211,7 +211,7 @@ public void oneselfConfig(Config config){ ## 版本说明 -### `2.4.1-RELEASE` 版本 +### `2.4.2-RELEASE` 版本 1. 新增`Mybatis`、`Mybatis-Plus`、`Tk-Mybatis`扩展新增可重写覆盖主程序的配置(重写后会当前插件私有, 不影响主程序) 2. 修复`Mybatis-Plus`批量插入的bug diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml index c9f36c4af52f1ff6e4558ea80ada89733a7ae412..52067942e1eb3e984a9dabd033c4aa944ccedd15 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues springboot-plugin-framework-extension-mybatis - 2.4.1-RELEASE + 2.4.2-RELEASE jar 插件扩展-spring boot mybatis 集成扩展 @@ -64,7 +64,7 @@ 3.1.0 1.6 - 2.4.1-RELEASE + 2.4.2-RELEASE 2.0.1 3.4.1 2.1.5 diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/CommonRegister.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/CommonRegister.java new file mode 100644 index 0000000000000000000000000000000000000000..a9ef69e0b871b7a97ed8f5b251117bfb9ec5179b --- /dev/null +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/CommonRegister.java @@ -0,0 +1,27 @@ +package com.gitee.starblues.extension.mybatis; + +import com.gitee.starblues.factory.PluginRegistryInfo; +import com.gitee.starblues.factory.SpringBeanRegister; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionTemplate; + +/** + * 公共注册 + * @author starBlues + * @version 2.4.2 + */ +public class CommonRegister { + + private CommonRegister(){} + + + public static void commonRegister(PluginRegistryInfo pluginRegistryInfo, + SqlSessionFactory sqlSessionFactory, + SqlSessionTemplate sqlSessionTemplate){ + // 注册SqlSessionFactory + SpringBeanRegister springBeanRegister = pluginRegistryInfo.getSpringBeanRegister(); + springBeanRegister.registerSingleton("sqlSessionFactory", sqlSessionFactory); + springBeanRegister.registerSingleton("sqlSession", sqlSessionTemplate); + } + +} diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/MybatisProcessor.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/MybatisProcessor.java index db83b7324b5387c644b0db8feb34407c3f68bbe3..1d2ddc078e3a2c83f967763a24572b80ae5e0f24 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/MybatisProcessor.java +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/MybatisProcessor.java @@ -92,6 +92,7 @@ public class MybatisProcessor implements PluginBeanRegistrarExtend { mapperHandler.processMapper(pluginRegistryInfo, (holder, mapperClass) -> { mapperHandler.commonProcessMapper(holder, mapperClass, sqlSessionFactory, sqlSessionTemplate); }); + CommonRegister.commonRegister(pluginRegistryInfo, sqlSessionFactory, sqlSessionTemplate); } finally { Resources.setDefaultClassLoader(defaultClassLoader); } diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/mybatisplus/MybatisPlusProcessor.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/mybatisplus/MybatisPlusProcessor.java index e372ec62660bd7fc2d2c66335cc85dfbc866e3f3..e4b263eaf42a1ae3548322a4a52186d5ffe3b835 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/mybatisplus/MybatisPlusProcessor.java +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/mybatisplus/MybatisPlusProcessor.java @@ -3,11 +3,8 @@ package com.gitee.starblues.extension.mybatis.mybatisplus; import com.baomidou.mybatisplus.autoconfigure.MybatisPlusProperties; import com.baomidou.mybatisplus.core.MybatisConfiguration; import com.baomidou.mybatisplus.core.config.GlobalConfig; -import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; -import com.baomidou.mybatisplus.core.incrementer.IKeyGenerator; -import com.baomidou.mybatisplus.core.injector.ISqlInjector; -import com.baomidou.mybatisplus.core.toolkit.GlobalConfigUtils; import com.baomidou.mybatisplus.extension.spring.MybatisSqlSessionFactoryBean; +import com.gitee.starblues.extension.mybatis.CommonRegister; import com.gitee.starblues.extension.mybatis.MapperHandler; import com.gitee.starblues.extension.mybatis.PluginFollowCoreConfig; import com.gitee.starblues.extension.mybatis.PluginResourceFinder; @@ -22,7 +19,6 @@ import org.apache.ibatis.session.SqlSessionFactory; import org.mybatis.spring.SqlSessionTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.BeanUtils; import org.springframework.context.support.GenericApplicationContext; import org.springframework.core.io.Resource; @@ -105,6 +101,7 @@ public class MybatisPlusProcessor implements PluginBeanRegistrarExtend { mapperHandler.processMapper(pluginRegistryInfo, (holder, mapperClass) -> { mapperHandler.commonProcessMapper(holder, mapperClass, sqlSessionFactory, sqlSessionTemplate); }); + CommonRegister.commonRegister(pluginRegistryInfo, sqlSessionFactory, sqlSessionTemplate); } finally { Resources.setDefaultClassLoader(defaultClassLoader); } diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/tkmyabtis/TkMybatisProcessor.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/tkmyabtis/TkMybatisProcessor.java index 427b60ff01e3418b6a455953e9e4745eaea6d226..1005696a86edaee9159b5dcc433b5b956f6f8421 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/tkmyabtis/TkMybatisProcessor.java +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-mybatis/src/main/java/com/gitee/starblues/extension/mybatis/tkmyabtis/TkMybatisProcessor.java @@ -1,9 +1,6 @@ package com.gitee.starblues.extension.mybatis.tkmyabtis; -import com.gitee.starblues.extension.mybatis.MapperHandler; -import com.gitee.starblues.extension.mybatis.PluginFollowCoreConfig; -import com.gitee.starblues.extension.mybatis.PluginResourceFinder; -import com.gitee.starblues.extension.mybatis.SpringBootMybatisExtension; +import com.gitee.starblues.extension.mybatis.*; import com.gitee.starblues.factory.PluginRegistryInfo; import com.gitee.starblues.factory.process.pipe.bean.PluginBeanRegistrarExtend; import com.gitee.starblues.utils.SpringBeanUtils; @@ -114,6 +111,7 @@ public class TkMybatisProcessor implements PluginBeanRegistrarExtend { mapperHandler.processMapper(pluginRegistryInfo, (holder, mapperClass) -> { processMapper(holder, mapperClass, mapperHelper, sqlSessionFactory, sqlSessionTemplate); }); + CommonRegister.commonRegister(pluginRegistryInfo, sqlSessionFactory, sqlSessionTemplate); } finally { Resources.setDefaultClassLoader(defaultClassLoader); Thread.currentThread().setContextClassLoader(contextClassLoader); diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/README.md b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/README.md index 14eb258c2e9b6c27ef58a13f086040d920285c0e..1e9b69b00c85cc4dc1ec092fb7d396ee83bb2539 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/README.md +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/README.md @@ -104,7 +104,7 @@ public class ResourceConfig implements SpringBootThymeleafConfig { ## 版本说明 -### `2.4.1-RELEASE` 版本 +### `2.4.2-RELEASE` 版本 1. 修复静态资源无法访问的bug #### `2.4.0-RELEASE` 版本 diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/pom.xml b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/pom.xml index 83b9e4428926e6c4ed1542ea3f3f52df8126ec94..2b13e49ffb027d632493aba979e130a54a106b0a 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/pom.xml +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues springboot-plugin-framework-extension-resources - 2.4.1-RELEASE + 2.4.2-RELEASE jar 插件扩展-通过url读取插件中的静态资源 @@ -69,7 +69,7 @@ 5.0.7.RELEASE 4.0.1 - 2.4.1-RELEASE + 2.4.2-RELEASE 2.0.3.RELEASE 2.1.1.RELEASE diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/src/main/java/com/gitee/starblues/extension/resources/resolver/PluginResourceResolver.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/src/main/java/com/gitee/starblues/extension/resources/resolver/PluginResourceResolver.java index 7b4a32c004c036d2caa7d666078cd4263f9ddf11..182ea6ea43511057a1fc957cbe5be5e2371822b1 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/src/main/java/com/gitee/starblues/extension/resources/resolver/PluginResourceResolver.java +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/src/main/java/com/gitee/starblues/extension/resources/resolver/PluginResourceResolver.java @@ -194,6 +194,7 @@ public class PluginResourceResolver extends AbstractResourceResolver { /** * 每新增一个插件, 都需要调用该方法,来解析该插件的 StaticResourceConfig 配置。并将其保存到 StaticResourceConfig bean 中。 * @param pluginRegistryInfo 插件信息 + * @param staticResourceConfig 静态资源配置 */ public static synchronized void parse(PluginRegistryInfo pluginRegistryInfo, StaticResourceConfig staticResourceConfig){ diff --git a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/src/main/java/com/gitee/starblues/extension/resources/thymeleaf/ThymeleafProcessor.java b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/src/main/java/com/gitee/starblues/extension/resources/thymeleaf/ThymeleafProcessor.java index 995d99169facffb2e0fdc03a1c529ed35e4f0b01..5075825204b416c66401c57ce20ab944bf58bad7 100644 --- a/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/src/main/java/com/gitee/starblues/extension/resources/thymeleaf/ThymeleafProcessor.java +++ b/springboot-plugin-framework-extension/springboot-plugin-framework-extension-resources/src/main/java/com/gitee/starblues/extension/resources/thymeleaf/ThymeleafProcessor.java @@ -2,6 +2,7 @@ package com.gitee.starblues.extension.resources.thymeleaf; import com.gitee.starblues.factory.PluginRegistryInfo; import com.gitee.starblues.factory.process.pipe.PluginPipeProcessorExtend; +import com.gitee.starblues.utils.ClassUtils; import com.gitee.starblues.utils.OrderPriority; import com.gitee.starblues.utils.SpringBeanUtils; import org.slf4j.Logger; @@ -93,7 +94,7 @@ public class ThymeleafProcessor implements PluginPipeProcessorExtend { resolver.setCheckExistence(true); Set templateResolvers = getITemplateResolvers(springTemplateEngine); if(templateResolvers != null){ - springTemplateEngine.addTemplateResolver(resolver); + templateResolvers.add(resolver); } else { LOGGER.error("You can't use Thymeleaf, because not fount 'Set' " + "from Bean:SpringTemplateEngine by reflect"); @@ -102,7 +103,6 @@ public class ThymeleafProcessor implements PluginPipeProcessorExtend { pluginRegistryInfo.addExtension(TEMPLATE_RESOLVER_BEAN, resolver); } - @SuppressWarnings("unchecked") @Override public void unRegistry(PluginRegistryInfo pluginRegistryInfo) throws Exception { Object resolver = pluginRegistryInfo.getExtension(TEMPLATE_RESOLVER_BEAN); @@ -112,7 +112,7 @@ public class ThymeleafProcessor implements PluginPipeProcessorExtend { try { SpringTemplateEngine springTemplateEngine = getSpringTemplateEngine(pluginRegistryInfo); Set templateResolvers = getITemplateResolvers(springTemplateEngine); - if(templateResolvers != null){ + if(templateResolvers != null && resolver instanceof ClassLoaderTemplateResolver){ templateResolvers.remove(resolver); } } catch (Exception e){ @@ -139,14 +139,8 @@ public class ThymeleafProcessor implements PluginPipeProcessorExtend { if(springTemplateEngine == null){ return null; } - Field templateResolversField = ReflectionUtils.findField(springTemplateEngine.getClass(), "templateResolvers"); - if (templateResolversField == null) { - return null; - } - if(!templateResolversField.isAccessible()){ - templateResolversField.setAccessible(true); - } - return (Set) templateResolversField.get(springTemplateEngine); + return ClassUtils.getReflectionField(springTemplateEngine, "templateResolvers"); } + } diff --git a/springboot-plugin-framework/pom.xml b/springboot-plugin-framework/pom.xml index 1f5eaf3a55713101e0f5c596d16f1a85c28e3e8b..fcda2b0e65952b88373600f8a3d5e8e2863f7c93 100644 --- a/springboot-plugin-framework/pom.xml +++ b/springboot-plugin-framework/pom.xml @@ -13,7 +13,7 @@ com.gitee.starblues springboot-plugin-framework jar - 2.4.1-RELEASE + 2.4.2-RELEASE spring boot 插件式开发集成包 diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/PluginRegistryInfo.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/PluginRegistryInfo.java index 352310349475960fa23666a80dddd30fee7c54c0..5d7ca4de501b7830ea81aaf3b52ee9b87b77f9a6 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/PluginRegistryInfo.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/PluginRegistryInfo.java @@ -70,10 +70,6 @@ public class PluginRegistryInfo { */ private final Map processorInfo = new ConcurrentHashMap<>(8); - /** - * websocket路径 - */ - private final List websocketPaths = new ArrayList<>(); private PluginRegistryInfo(PluginWrapper pluginWrapper, PluginManager pluginManager, @@ -328,12 +324,4 @@ public class PluginRegistryInfo { } } - public void addWebsocketPath(String path) { - websocketPaths.add(path); - } - - public List getWebsocketPaths() { - return websocketPaths; - } - } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/ConfigFileBeanRegistrar.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/ConfigFileBeanRegistrar.java index f6cee2a61714cea566bb979630f3981003e7a2e2..ecfb5aa2c2c3a913609431e96fbf179a9205a53c 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/ConfigFileBeanRegistrar.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/ConfigFileBeanRegistrar.java @@ -8,10 +8,16 @@ import com.gitee.starblues.factory.process.pipe.bean.configuration.PluginConfigD import com.gitee.starblues.factory.process.pipe.bean.configuration.YamlConfigurationParser; import com.gitee.starblues.factory.process.pipe.classs.group.ConfigDefinitionGroup; import com.gitee.starblues.integration.IntegrationConfiguration; +import com.gitee.starblues.realize.ConfigDefinitionTip; +import com.gitee.starblues.utils.ClassUtils; import org.pf4j.RuntimeMode; import org.pf4j.util.StringUtils; +import org.springframework.beans.BeanUtils; import org.springframework.context.ApplicationContext; +import org.springframework.util.ReflectionUtils; +import java.beans.PropertyDescriptor; +import java.lang.reflect.Field; import java.util.List; /** @@ -72,11 +78,28 @@ public class ConfigFileBeanRegistrar implements PluginBeanRegistrar { } name = name + "@" + pluginRegistryInfo.getPluginWrapper().getPluginId(); SpringBeanRegister springBeanRegister = pluginRegistryInfo.getSpringBeanRegister(); + setConfigDefinitionTip(pluginRegistryInfo, parseObject); springBeanRegister.registerSingleton(name, parseObject); pluginRegistryInfo.addConfigSingleton(parseObject); return name; } + /** + * 设置小工具类 + * @param parseObject 当前的配置对象 + */ + private void setConfigDefinitionTip(PluginRegistryInfo pluginRegistryInfo, Object parseObject) { + Class aClass = parseObject.getClass(); + List fields = ClassUtils.getAllFields(aClass); + ConfigDefinitionTip configDefinitionTip = new ConfigDefinitionTip(pluginRegistryInfo); + for (Field field : fields) { + if(field.getType() == ConfigDefinitionTip.class){ + field.setAccessible(true); + ReflectionUtils.setField(field, parseObject, configDefinitionTip); + } + } + } + /** * 根据项目运行环境模式来获取配置文件 * @param configDefinition 配置的注解 diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/inset/PluginInsetBean.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/inset/PluginInsetBean.java index 924086a61ef9cfe8df686b2ebb25813156bb04bb..a745d3f4225dc3b5f186aa782a189003a60c696a 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/inset/PluginInsetBean.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/bean/inset/PluginInsetBean.java @@ -16,6 +16,7 @@ public interface PluginInsetBean { /** * 得到bean对象 + * @param pluginRegistryInfo pluginRegistryInfo * @return 对象 */ Object getBean(PluginRegistryInfo pluginRegistryInfo); diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/interceptor/PluginInterceptorRegistration.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/interceptor/PluginInterceptorRegistration.java index ba067c7c41ff697e5717ef47bbb4cc9169385d3d..ee8647e093c567c707082f2ca6341f6e3236eb09 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/interceptor/PluginInterceptorRegistration.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/interceptor/PluginInterceptorRegistration.java @@ -59,6 +59,8 @@ public class PluginInterceptorRegistration { /** * Add URL patterns to which the registered interceptor should apply to. + * @param patterns patterns + * @return PluginInterceptorRegistration */ public PluginInterceptorRegistration addPathPatterns(String... patterns) { if(type == PluginInterceptorRegistry.Type.GLOBAL){ @@ -76,6 +78,8 @@ public class PluginInterceptorRegistration { /** * Add URL patterns to which the registered interceptor should not apply to. + * @param patterns patterns + * @return PluginInterceptorRegistration */ public PluginInterceptorRegistration excludePathPatterns(String... patterns) { if(type == PluginInterceptorRegistry.Type.GLOBAL){ @@ -96,6 +100,8 @@ public class PluginInterceptorRegistration { * advanced property required only if using custom PathMatcher implementations * that support mapping metadata other than the Ant path patterns supported * by default. + * @param pathMatcher pathMatcher + * @return PluginInterceptorRegistration */ public PluginInterceptorRegistration pathMatcher(PathMatcher pathMatcher) { this.pathMatcher = pathMatcher; @@ -104,7 +110,9 @@ public class PluginInterceptorRegistration { /** * Specify an order position to be used. Default is 0. + * @param order order * @since 5.0 + * @return PluginInterceptorRegistration */ public PluginInterceptorRegistration order(int order){ this.order = order; @@ -114,6 +122,7 @@ public class PluginInterceptorRegistration { /** * Return the order position to be used. * @since 5.0 + * @return int */ protected int getOrder() { return this.order; @@ -123,6 +132,7 @@ public class PluginInterceptorRegistration { /** * Build the underlying interceptor. If URL patterns are provided, the returned * type is {@link MappedInterceptor}; otherwise {@link HandlerInterceptor}. + * @return object 为 {@link MappedInterceptor} or {@link HandlerInterceptor} */ protected Object getInterceptor() { if(type == PluginInterceptorRegistry.Type.PLUGIN){ diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/interceptor/PluginInterceptorRegistry.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/interceptor/PluginInterceptorRegistry.java index f2f5ca70a252726d38f855641cc2847c3407769a..f95ecc8476f834a1cb6623e1de465437c4fe3721 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/interceptor/PluginInterceptorRegistry.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/pipe/interceptor/PluginInterceptorRegistry.java @@ -27,10 +27,10 @@ public class PluginInterceptorRegistry { this.pluginRestApiPrefix = pluginRestApiPrefix; } - /** * Adds the provided {@link HandlerInterceptor}. * @param interceptor the interceptor to add + * @param type type {@link Type} * @return An {@link InterceptorRegistration} that allows you optionally configure the * registered interceptor further for example adding URL patterns it should apply to. */ @@ -44,6 +44,8 @@ public class PluginInterceptorRegistry { /** * Adds the provided {@link WebRequestInterceptor}. * @param interceptor the interceptor to add + * @param type type {@link Type} + * * @return An {@link InterceptorRegistration} that allows you optionally configure the * registered interceptor further for example adding URL patterns it should apply to. */ @@ -57,6 +59,7 @@ public class PluginInterceptorRegistry { /** * Return all registered interceptors. + * @return interceptors */ public List getInterceptors() { return this.registrations.stream() diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/PluginPostProcessorFactory.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/PluginPostProcessorFactory.java index 750b1dcf1ba0823b8153bd8e0c110ee9218d403d..ffa22824deec3988dd5de738bbe4061335d8d23a 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/PluginPostProcessorFactory.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/PluginPostProcessorFactory.java @@ -3,6 +3,7 @@ package com.gitee.starblues.factory.process.post; import com.gitee.starblues.extension.ExtensionInitializer; import com.gitee.starblues.factory.PluginRegistryInfo; import com.gitee.starblues.factory.process.post.bean.*; +import com.gitee.starblues.integration.IntegrationConfiguration; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.context.ApplicationContext; @@ -22,9 +23,11 @@ public class PluginPostProcessorFactory implements PluginPostProcessor { private final List pluginPostProcessors = new ArrayList<>(); private final ApplicationContext mainApplicationContext; + private final IntegrationConfiguration integrationConfiguration; public PluginPostProcessorFactory(ApplicationContext mainApplicationContext){ this.mainApplicationContext = mainApplicationContext; + this.integrationConfiguration = mainApplicationContext.getBean(IntegrationConfiguration.class); } @Override @@ -32,7 +35,10 @@ public class PluginPostProcessorFactory implements PluginPostProcessor { // 以下顺序不能更改 pluginPostProcessors.add(new PluginInvokePostProcessor(mainApplicationContext)); pluginPostProcessors.add(new PluginControllerPostProcessor(mainApplicationContext)); - pluginPostProcessors.add(new PluginWebSocketProcessor(mainApplicationContext)); + if(integrationConfiguration.enableWebSocket()){ + // 如果配置启用webSocket的功能, 则进行引入 + pluginPostProcessors.add(new PluginWebSocketProcessor(mainApplicationContext)); + } // 主要触发启动监听事件,因此在最后一个执行。配合 OneselfListenerStopEventProcessor 该类触发启动、停止事件。 pluginPostProcessors.add(new PluginOneselfStartEventProcessor()); // 添加扩展 diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginControllerPostProcessor.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginControllerPostProcessor.java index 0928fdcc4a263e7354c2b6e28355fd827918c509..77a47d57b2bd9ca01f761d7c73887f94fd86eab1 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginControllerPostProcessor.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginControllerPostProcessor.java @@ -7,6 +7,7 @@ import com.gitee.starblues.factory.process.pipe.classs.group.ControllerGroup; import com.gitee.starblues.factory.process.post.PluginPostProcessor; import com.gitee.starblues.factory.process.post.bean.model.ControllerWrapper; import com.gitee.starblues.integration.IntegrationConfiguration; +import com.gitee.starblues.utils.ClassUtils; import com.gitee.starblues.utils.CommonUtils; import org.pf4j.util.StringUtils; import org.slf4j.Logger; @@ -216,14 +217,11 @@ public class PluginControllerPostProcessor implements PluginPostProcessor { if(StringUtils.isNullOrEmpty(pathPrefix)){ return; } - InvocationHandler invocationHandler = Proxy.getInvocationHandler(requestMapping); Set definePaths = new HashSet<>(); definePaths.addAll(Arrays.asList(requestMapping.path())); definePaths.addAll(Arrays.asList(requestMapping.value())); try { - Field field = invocationHandler.getClass().getDeclaredField("memberValues"); - field.setAccessible(true); - Map memberValues = (Map) field.get(invocationHandler); + Map memberValues = ClassUtils.getAnnotationsUpdater(requestMapping); String[] newPath = new String[definePaths.size()]; int i = 0; for (String definePath : definePaths) { diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginWebSocketProcessor.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginWebSocketProcessor.java index 2e7b0c19aabd48978e7ba6e1c03e191d5afb2de1..f8db4c92e0441a76aa85615fbe909c04dcc4ca44 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginWebSocketProcessor.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/factory/process/post/bean/PluginWebSocketProcessor.java @@ -3,37 +3,22 @@ package com.gitee.starblues.factory.process.post.bean; import com.gitee.starblues.factory.PluginRegistryInfo; import com.gitee.starblues.factory.process.pipe.classs.group.WebSocketGroup; import com.gitee.starblues.factory.process.post.PluginPostProcessor; -import java.io.IOException; -import java.io.InputStream; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; + +import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; import javax.servlet.ServletContext; import javax.websocket.DeploymentException; import javax.websocket.EndpointConfig; import javax.websocket.Session; -import javax.websocket.server.PathParam; import javax.websocket.server.ServerContainer; import javax.websocket.server.ServerEndpoint; import javax.websocket.server.ServerEndpointConfig; + +import com.gitee.starblues.utils.ClassUtils; +import org.pf4j.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.asm.AnnotationVisitor; -import org.springframework.asm.ClassReader; -import org.springframework.asm.ClassVisitor; -import org.springframework.asm.ClassWriter; -import org.springframework.asm.MethodVisitor; -import org.springframework.asm.Opcodes; -import org.springframework.asm.Type; import org.springframework.beans.BeansException; import org.springframework.context.ApplicationContext; import org.springframework.web.context.WebApplicationContext; @@ -43,14 +28,14 @@ import org.springframework.web.socket.server.standard.ServerEndpointExporter; * 插件中websocket处理者 * * @author sousouki + * @version 2.4.2 */ public class PluginWebSocketProcessor implements PluginPostProcessor { private static final Logger log = LoggerFactory.getLogger(PluginWebSocketProcessor.class); public static final String KEY = "PluginWsConfigProcessor"; - - private static final int ASM_API_VERSION = Opcodes.ASM7; + private static final String WEB_SOCKET_PATH = "WEB_SOCKET_PATH"; private final ApplicationContext applicationContext; @@ -65,304 +50,142 @@ public class PluginWebSocketProcessor implements PluginPostProcessor { @Override public void registry(List pluginRegistryInfos) throws Exception { - try { - applicationContext.getBean(ServerEndpointExporter.class); - } catch (BeansException e) { - log.debug("The required bean of {} not found, if you want to use plugin websocket, please create it.", ServerEndpointExporter.class.getName()); - return; - } - pluginRegistryInfos.forEach(pluginRegistryInfo -> { + ServerContainer serverContainer = getServerContainer(); + if (serverContainer == null) return; + + for (PluginRegistryInfo pluginRegistryInfo : pluginRegistryInfos) { + Map webSocketPathMap = new HashMap<>(); + List> websocketClasses = pluginRegistryInfo.getGroupClasses(WebSocketGroup.GROUP_ID); String pluginId = pluginRegistryInfo.getPluginWrapper().getPluginId(); - if (applicationContext instanceof WebApplicationContext) { - WebApplicationContext webApplicationContext = (WebApplicationContext) applicationContext; - ServletContext servletContext = webApplicationContext.getServletContext(); - if (servletContext == null) { - log.warn("Servlet context is null."); + websocketClasses.forEach(websocketClass -> { + ServerEndpoint serverEndpoint = websocketClass.getDeclaredAnnotation(ServerEndpoint.class); + if (serverEndpoint == null) { + log.warn("WebSocket class {} doesn't has annotation {}", websocketClass.getName(), ServerEndpoint.class.getName()); return; } - Object obj = servletContext.getAttribute("javax.websocket.server.ServerContainer"); - if (obj instanceof ServerContainer) { - ServerContainer serverContainer = (ServerContainer) obj; - List> websocketClasses = pluginRegistryInfo.getGroupClasses(WebSocketGroup.GROUP_ID); - websocketClasses.forEach(websocketClass -> { - ServerEndpoint serverEndpoint = websocketClass.getDeclaredAnnotation(ServerEndpoint.class); - if (serverEndpoint == null) { - log.warn("WebSocket class {} doesn't has annotation {}", websocketClass.getName(), ServerEndpoint.class.getName()); - return; - } - String websocketPath = serverEndpoint.value(); - UriTemplate uriTemplate; - try { - uriTemplate = new UriTemplate(websocketPath); - } catch (DeploymentException e) { - log.error("Websocket path validate failed.", e); - return; - } - String websocketTemplatePath = uriTemplate.getPath(); - Map pathParam = uriTemplate.getParamMap(); - String newWebsocketPath = "/".concat(pluginId).concat(websocketTemplatePath); - String pluginPath = pluginRegistryInfo.getPluginWrapper().getPluginPath().toString(); - Class proxyServerEndpoint = createProxyClass(pluginRegistryInfo, pluginPath, websocketClass, newWebsocketPath, pathParam); - if (proxyServerEndpoint == null) { - log.warn("Proxy class for websocket class {} is null.", websocketClass.getName()); - return; - } - try { - serverContainer.addEndpoint(proxyServerEndpoint); - pluginRegistryInfo.addWebsocketPath(newWebsocketPath); - log.info("Succeed to create websocket service for path {}", newWebsocketPath); - } catch (DeploymentException e) { - log.error("Create websocket service for websocket class " + websocketClass.getName() + " failed.", e); - } - }); + String sourcePath = serverEndpoint.value(); + if (StringUtils.isNullOrEmpty(sourcePath)) { + return; } - } - }); - } + String processPath = sourcePath; + if(!processPath.startsWith("/")){ + processPath = "/".concat(processPath); + } + UriTemplate uriTemplate; - @Override - public void unRegistry(List pluginRegistryInfos) throws Exception { - pluginRegistryInfos.forEach(pluginRegistryInfo -> { - List websocketPaths = pluginRegistryInfo.getWebsocketPaths(); - websocketPaths.forEach(websocketPath -> { try { - if (applicationContext instanceof WebApplicationContext) { - WebApplicationContext webApplicationContext = (WebApplicationContext) applicationContext; - ServletContext servletContext = webApplicationContext.getServletContext(); - if (servletContext == null) { - log.warn("Servlet context is null."); - return; - } - Object obj = servletContext.getAttribute("javax.websocket.server.ServerContainer"); - if (obj instanceof ServerContainer) { - ServerContainer serverContainer = (ServerContainer) obj; - Map configExactMatchMap = (Map) reflectFieldValue(serverContainer, "configExactMatchMap"); - configExactMatchMap.remove(websocketPath); - log.debug("Removed websocket config for path {}", websocketPath); - - Map> configTemplateMatchMap = (Map>) reflectFieldValue(serverContainer, "configTemplateMatchMap"); - configTemplateMatchMap.forEach((key, value) -> { - value.remove(websocketPath); - }); - - Map endpointSessionMap = (Map) reflectParentFieldValue(serverContainer, "endpointSessionMap"); - endpointSessionMap.remove(websocketPath); - log.debug("Removed websocket session for path {}", websocketPath); - - Map sessions = (Map) reflectParentFieldValue(serverContainer, "sessions"); - for (Map.Entry entry : sessions.entrySet()) { - Session session = entry.getKey(); - EndpointConfig endpointConfig = (EndpointConfig) reflectFieldValue(session, "endpointConfig"); - ServerEndpointConfig perEndpointConfig = (ServerEndpointConfig) reflectFieldValue(endpointConfig, "perEndpointConfig"); - String path = (String) reflectFieldValue(perEndpointConfig, "path"); - if (path.equals(websocketPath)) { - session.close(); - log.debug("Closed websocket session {} for path {}", session.getId(), websocketPath); - sessions.remove(session); - log.debug("Removed websocket session {} for path {}", session.getId(), websocketPath); - } - } - log.info("Remove websocket for path {} success.", websocketPath); - } - } - } catch (IllegalAccessException | NoSuchFieldException | IOException e) { - log.error("Remove websocket failed for path " + websocketPath, e); + uriTemplate = new UriTemplate(processPath); + } catch (DeploymentException e) { + log.error("Websocket path validate failed.", e); + return; } - }); - }); - } - - private Object reflectFieldValue(Object obj, String fieldName) throws NoSuchFieldException, IllegalAccessException { - Field field = obj.getClass().getDeclaredField(fieldName); - if (!field.isAccessible()) { - field.setAccessible(true); - } - return field.get(obj); - } - - private Object reflectParentFieldValue(Object obj, String fieldName) throws NoSuchFieldException, IllegalAccessException { - Field field = obj.getClass().getSuperclass().getDeclaredField(fieldName); - if (!field.isAccessible()) { - field.setAccessible(true); - } - return field.get(obj); - } - - private Class createProxyClass(PluginRegistryInfo pluginRegistryInfo, String pluginPath, Class websocketClass, String newWebsocketPath, Map pathParam) { - String simpleName = websocketClass.getSimpleName(); - String className = websocketClass.getName(); - String basePackage = className.substring(0, className.lastIndexOf(simpleName) - 1); - try (JarFile jarFile = new JarFile(pluginPath)) { - Enumeration jarEntries = jarFile.entries(); - while (jarEntries.hasMoreElements()) { - JarEntry entry = jarEntries.nextElement(); - String jarEntryName = entry.getName(); - if (jarEntryName.endsWith(simpleName.concat(".class")) && jarEntryName.replaceAll("/", ".").startsWith(basePackage)) { - InputStream inputStream = jarFile.getInputStream(entry); - if (inputStream == null) { - log.warn("Class stream for {} is null.", websocketClass.getName()); - return null; - } - Class proxyClass = createProxyClass(pluginRegistryInfo, inputStream, websocketClass, newWebsocketPath, pathParam); - log.debug("Created proxy class {} for websocket class {}", proxyClass.getName(), className); - return proxyClass; + String newWebsocketPath = "/".concat(pluginId).concat(processPath); + String newWebsocketTemplatePath = "/".concat(pluginId).concat(uriTemplate.getPath()); + Map annotationsUpdater = null; + try { + annotationsUpdater = ClassUtils.getAnnotationsUpdater(serverEndpoint); + } catch (Exception e) { + log.error("Process and update websocket path '{}' annotation exception.", sourcePath, e); + return; } - } - } catch (IOException | NoSuchMethodException | InvocationTargetException | IllegalAccessException e) { - log.error("Create proxy class for websocket class " + className + "error", e); - return null; - } - return null; - } - - private Class createProxyClass(PluginRegistryInfo pluginRegistryInfo, InputStream inputStream, Class websocketClass, String newWebsocketPath, Map pathParam) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException { - ClassReader cr = new ClassReader(inputStream); - ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); - String className = websocketClass.getName(); - String proxyClassName = className.concat("$PluginProxyServerEndpoint$".concat(String.valueOf(System.currentTimeMillis()))); - ClassVisitor cv = new ServerEndpointProxyClassVisitor(ASM_API_VERSION, cw, websocketClass, proxyClassName, newWebsocketPath, pathParam); - cr.accept(cv, 0); - byte[] classData = cw.toByteArray(); - return defineClass(pluginRegistryInfo, proxyClassName, classData); - } - - private Class defineClass(PluginRegistryInfo pluginRegistryInfo, String proxyClassName, byte[] classData) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException { - ClassLoader classLoader = pluginRegistryInfo.getPluginClassLoader(); - Method defineClassMethod = ClassLoader.class.getDeclaredMethod("defineClass", String.class, byte[].class, int.class, int.class); - if (!defineClassMethod.isAccessible()) { - defineClassMethod.setAccessible(true); + try { + annotationsUpdater.put("value", newWebsocketPath); + serverContainer.addEndpoint(websocketClass); + webSocketPathMap.put(newWebsocketPath, newWebsocketTemplatePath); + log.info("Succeed to create websocket service for path {}", newWebsocketPath); + } catch (Exception e) { + log.error("Create websocket service for websocket class " + websocketClass.getName() + " failed.", e); + } finally { + annotationsUpdater.put("value", sourcePath); + } + }); + pluginRegistryInfo.addExtension(WEB_SOCKET_PATH, webSocketPathMap); } - return (Class) defineClassMethod.invoke(classLoader, proxyClassName, classData, 0, classData.length); } - /** - * 修改类名及类注解的值 - */ - private static class ServerEndpointProxyClassVisitor extends ClassVisitor { - - private final String proxyClassName; - private final String proxyClassInternalName; - private final String classInternalName; - private final String newPath; - private final Class websocketClass; - private final Map pathParam; - - private ServerEndpointProxyClassVisitor(int api, ClassVisitor classVisitor, Class websocketClass, String proxyClassName, String newPath, Map pathParam) { - super(api, classVisitor); - String classInternalName = Type.getInternalName(websocketClass); - this.proxyClassName = proxyClassName; - this.proxyClassInternalName = proxyClassName.replaceAll("\\.", "/"); - this.classInternalName = classInternalName; - this.newPath = newPath; - this.websocketClass = websocketClass; - this.pathParam = pathParam; - } - - @Override - public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) { - super.visit(version, access, proxyClassInternalName, signature, superName, interfaces); - log.debug("Changed class name from {} to {}", classInternalName, proxyClassInternalName); + @Override + public void unRegistry(List pluginRegistryInfos) throws Exception { + ServerContainer serverContainer = getServerContainer(); + if (serverContainer == null) { + log.warn("Not found ServerContainer, So websocket can't used!"); + return; } - @Override - public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { - AnnotationVisitor superAnnotationVisitor = super.visitAnnotation(descriptor, visible); - if (descriptor.equals(Type.getDescriptor(ServerEndpoint.class))) { - return new AnnotationVisitor(ASM_API_VERSION, superAnnotationVisitor) { - @Override - public void visit(String name, Object value) { - if ("value".equals(name)) { - value = newPath; - log.debug("Changed websocket path from {} to {} in for annotation {}", value, newPath, ServerEndpoint.class.getName()); + Map configExactMatchMap = ClassUtils.getReflectionField(serverContainer, "configExactMatchMap"); + Map> configTemplateMatchMap = + ClassUtils.getReflectionField(serverContainer, "configTemplateMatchMap"); + Map endpointSessionMap = ClassUtils.getReflectionField(serverContainer, "endpointSessionMap"); + Map sessions = ClassUtils.getReflectionField(serverContainer, "sessions"); + pluginRegistryInfos.forEach(pluginRegistryInfo -> { + Map webSocketPathMap = pluginRegistryInfo.getExtension(WEB_SOCKET_PATH); + webSocketPathMap.forEach((webSocketPath,newWebsocketTemplatePath)->{ + configExactMatchMap.remove(webSocketPath); + log.debug("Removed websocket config for path {}", webSocketPath); + configTemplateMatchMap.forEach((key, value) -> { + value.remove(newWebsocketTemplatePath); + }); + endpointSessionMap.remove(webSocketPath); + log.debug("Removed websocket session for path {}", webSocketPath); + + for (Map.Entry entry : sessions.entrySet()) { + Session session = entry.getKey(); + try { + if(closeSession(session, webSocketPath)){ + sessions.remove(session); + log.debug("Removed websocket session {} for path {}", session.getId(), webSocketPath); } - super.visit(name, value); + } catch (Exception e) { + log.debug("Close websocket session {} for path {} failure", session.getId(), webSocketPath, e); } - }; - } - return superAnnotationVisitor; - } - - @Override - public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { - MethodVisitor superMethodVisitor = super.visitMethod(access, name, descriptor, signature, exceptions); - return new ServerEndpointProxyMethodVisitor(ASM_API_VERSION, superMethodVisitor, websocketClass, proxyClassName, pathParam); - } - + } + log.info("Remove websocket for path {} success.", webSocketPath); + }); + }); } /** - * 替换成员变量及方法所属 + * 得到 Tomcat ServerContainer + * @return ServerContainer */ - private static class ServerEndpointProxyMethodVisitor extends MethodVisitor { - - private final String classInternalName; - private final String proxyClassInternalName; - private final Map pathParam; - - private ServerEndpointProxyMethodVisitor(int api, MethodVisitor methodVisitor, Class websocketClass, String proxyClassName, Map pathParam) { - super(api, methodVisitor); - String classInternalName = Type.getInternalName(websocketClass); - this.proxyClassInternalName = proxyClassName.replaceAll("\\.", "/"); - this.classInternalName = classInternalName; - this.pathParam = pathParam; + private ServerContainer getServerContainer() { + try { + applicationContext.getBean(ServerEndpointExporter.class); + } catch (BeansException e) { + log.debug("The required bean of {} not found, if you want to use plugin websocket, please create it.", ServerEndpointExporter.class.getName()); + return null; } - - @Override - public void visitFieldInsn(int opcode, String owner, String name, String descriptor) { - // 替换成员变量所属 - if (owner.equals(classInternalName)) { - super.visitFieldInsn(opcode, proxyClassInternalName, name, descriptor); - log.debug("Changed owner from {} to {} for field {}", classInternalName, proxyClassInternalName, name); - } else { - super.visitFieldInsn(opcode, owner, name, descriptor); - } + if (!(applicationContext instanceof WebApplicationContext)) { + return null; } - - @Override - public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface) { - // 替换方法所属 - if (owner.equals(classInternalName)) { - super.visitMethodInsn(opcode, proxyClassInternalName, name, descriptor, isInterface); - log.debug("Changed owner from {} to {} in method {}", classInternalName, proxyClassInternalName, name); - } else { - super.visitMethodInsn(opcode, owner, name, descriptor, isInterface); - } + WebApplicationContext webApplicationContext = (WebApplicationContext) applicationContext; + ServletContext servletContext = webApplicationContext.getServletContext(); + if (servletContext == null) { + log.warn("Servlet context is null."); + return null; } - - @Override - public AnnotationVisitor visitParameterAnnotation(int parameter, String descriptor, boolean visible) { - AnnotationVisitor superAnnotationVisitor = super.visitParameterAnnotation(parameter, descriptor, visible); - // 替换@PathParam注解中value的值 - if (descriptor.equals(Type.getDescriptor(PathParam.class))) { - return new ServerEndpointProxyParameterAnnotationVisitor(ASM_API_VERSION, superAnnotationVisitor, pathParam); - } - return super.visitParameterAnnotation(parameter, descriptor, visible); + Object obj = servletContext.getAttribute("javax.websocket.server.ServerContainer"); + if (!(obj instanceof ServerContainer)) { + return null; } - + return (ServerContainer) obj; } /** - * 将@PathParam("name")替换为@PathParam("0"),使其与uri对应 + * 关闭session + * @param session session + * @param websocketPath websocketPath 路径 + * @return 如果需要关闭并且关闭成功, 则返回true。 否则返回false + * @throws Exception 关闭异常 */ - private static class ServerEndpointProxyParameterAnnotationVisitor extends AnnotationVisitor { - - private final Map pathParam; - - private ServerEndpointProxyParameterAnnotationVisitor(int api, AnnotationVisitor annotationVisitor, Map pathParam) { - super(api, annotationVisitor); - this.pathParam = pathParam; - } - - @Override - public void visit(String name, Object value) { - if ("value".equals(name)) { - Integer index = pathParam.get(String.valueOf(value)); - if (index != null) { - value = String.valueOf(index); - log.debug("Changed path parameter {} to {}", value, index); - } - } - super.visit(name, value); - } + private boolean closeSession(Session session, String websocketPath) throws Exception{ + EndpointConfig endpointConfig = ClassUtils.getReflectionField(session, "endpointConfig"); + ServerEndpointConfig perEndpointConfig = ClassUtils.getReflectionField(endpointConfig, "perEndpointConfig"); + String path = ClassUtils.getReflectionField(perEndpointConfig, "path"); + if (path.equals(websocketPath)) { + session.close(); + log.info("Closed websocket session {} for path {}", session.getId(), websocketPath); + return true; + } + return false; } /** diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/AutoIntegrationConfiguration.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/AutoIntegrationConfiguration.java index 8c8f7e95670b6373d3bf452c7ee44f00c76936c6..dd121b276d4710d87f13c82058008d0ee42c58c4 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/AutoIntegrationConfiguration.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/AutoIntegrationConfiguration.java @@ -12,7 +12,7 @@ import java.util.Set; /** * 自动集成的配置 * @author starBlues - * @version 2.4.0 + * @version 2.4.2 */ @Component @ConfigurationProperties(prefix = "plugin") @@ -109,6 +109,12 @@ public class AutoIntegrationConfiguration extends DefaultIntegrationConfiguratio */ private List sortInitPluginIds; + /** + * 是否启用webSocket的功能. 如需启用, 则需要引入springboot支持的WebSocket依赖 + */ + @Value("${enableWebSocket:false}") + private Boolean enableWebSocket; + @Override public RuntimeMode environment() { return RuntimeMode.byName(runMode); @@ -124,7 +130,6 @@ public class AutoIntegrationConfiguration extends DefaultIntegrationConfiguratio return pluginConfigFilePath; } - @Override public boolean enable() { if(enable == null){ @@ -133,7 +138,6 @@ public class AutoIntegrationConfiguration extends DefaultIntegrationConfiguratio return enable; } - @Override public String uploadTempPath() { if(StringUtils.isNullOrEmpty(uploadTempPath)){ @@ -168,7 +172,6 @@ public class AutoIntegrationConfiguration extends DefaultIntegrationConfiguratio } } - @Override public Set enablePluginIds() { return enablePluginIds; @@ -196,9 +199,20 @@ public class AutoIntegrationConfiguration extends DefaultIntegrationConfiguratio @Override public boolean exactVersionAllowed() { + if(exactVersionAllowed == null){ + return false; + } return exactVersionAllowed; } + @Override + public boolean enableWebSocket() { + if(enableWebSocket == null){ + return false; + } + return enableWebSocket; + } + public String getRunMode() { return runMode; } @@ -310,4 +324,12 @@ public class AutoIntegrationConfiguration extends DefaultIntegrationConfiguratio public void setSortInitPluginIds(List sortInitPluginIds) { this.sortInitPluginIds = sortInitPluginIds; } + + public Boolean getEnableWebSocket() { + return enableWebSocket; + } + + public void setEnableWebSocket(Boolean enableWebSocket) { + this.enableWebSocket = enableWebSocket; + } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/ConfigurationBuilder.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/ConfigurationBuilder.java index f937fd1856c6abb0ac1dd9d32efa377fccfae4c3..10d04b7277715d7b3cf5873922fa9d439a231c78 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/ConfigurationBuilder.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/ConfigurationBuilder.java @@ -11,7 +11,7 @@ import java.util.Set; * 通过构造者进行配置插件初始化配置 * * @author starBlues - * @version 2.4.0 + * @version 2.4.2 */ public class ConfigurationBuilder extends DefaultIntegrationConfiguration{ @@ -35,6 +35,8 @@ public class ConfigurationBuilder extends DefaultIntegrationConfiguration{ private String version; private Boolean exactVersionAllowed; + private Boolean enableWebSocket; + public ConfigurationBuilder(Builder builder) { this.runtimeMode = Objects.requireNonNull(builder.runtimeMode, "runtimeMode can't be empty"); this.pluginPath = Objects.requireNonNull(builder.pluginPath, "pluginPath can't be empty"); @@ -59,6 +61,11 @@ public class ConfigurationBuilder extends DefaultIntegrationConfiguration{ } else { this.enableSwaggerRefresh = builder.enableSwaggerRefresh; } + if(builder.enableWebSocket == null){ + this.enableWebSocket = false; + } else { + this.enableWebSocket = builder.enableWebSocket; + } } public static Builder toBuilder(){ @@ -86,6 +93,8 @@ public class ConfigurationBuilder extends DefaultIntegrationConfiguration{ private String version; private Boolean exactVersionAllowed; + private Boolean enableWebSocket; + public Builder runtimeMode(RuntimeMode runtimeMode){ this.runtimeMode = runtimeMode; return this; @@ -156,6 +165,11 @@ public class ConfigurationBuilder extends DefaultIntegrationConfiguration{ return this; } + public Builder enableWebSocket(Boolean enableWebSocket){ + this.enableWebSocket = enableWebSocket; + return this; + } + public ConfigurationBuilder build(){ return new ConfigurationBuilder(this); } @@ -258,4 +272,13 @@ public class ConfigurationBuilder extends DefaultIntegrationConfiguration{ } return exactVersionAllowed; } + + @Override + public boolean enableWebSocket() { + if(enableWebSocket == null){ + return super.enableWebSocket(); + } else { + return enableWebSocket; + } + } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/DefaultIntegrationConfiguration.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/DefaultIntegrationConfiguration.java index 6beb6954eef15d080ce6b1c517ed55406dae5ae9..1701f592cd17207a3c2b942a7f09c914e2809d79 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/DefaultIntegrationConfiguration.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/DefaultIntegrationConfiguration.java @@ -7,7 +7,7 @@ import java.util.Set; * 默认的插件集成配置。给非必须配置设置了默认值 * * @author starBlues - * @version 2.4.0 + * @version 2.4.2 */ public abstract class DefaultIntegrationConfiguration implements IntegrationConfiguration{ @@ -65,4 +65,9 @@ public abstract class DefaultIntegrationConfiguration implements IntegrationConf public boolean exactVersionAllowed() { return false; } + + @Override + public boolean enableWebSocket() { + return false; + } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/IntegrationConfiguration.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/IntegrationConfiguration.java index 727e6ce23caecceab8e6baf613861769bf96a695..8fbedba96b2cbd82e42d2335e7d639f0cce7a72f 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/IntegrationConfiguration.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/IntegrationConfiguration.java @@ -9,7 +9,7 @@ import java.util.Set; /** * 插件集成时的配置接口。插件集成的配置接口 * @author starBlues - * @version 2.4.0 + * @version 2.4.2 */ public interface IntegrationConfiguration { @@ -99,11 +99,17 @@ public interface IntegrationConfiguration { String version(); /** - * 设置为true表示插件设置的requires的版本号完全匹配version版本号才可允许插件安装, 即: requires=x.y.z - * 设置为false表示插件设置的requires的版本号小于等于version值, 插件就可安装, 即requires<=x.y.z + * 设置为true表示插件设置的requires的版本号完全匹配version版本号才可允许插件安装, 即: [requires]=[x.y.z] + * 设置为false表示插件设置的requires的版本号小于等于version值, 插件就可安装, 即[requires]小于等于[x.y.z] * 默认为false * @return true or false */ boolean exactVersionAllowed(); + /** + * 是否启用webSocket功能. 如需启用, 则需要引入springboot支持的WebSocket依赖 + * @return 启用返回true,不启用返回false + */ + boolean enableWebSocket(); + } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/module/PluginInfo.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/module/PluginInfo.java index 0d954bb97d0485b0991c2b57fca615cec1df718d..abc527ad541b3f865d342aff440d393a875d6398 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/module/PluginInfo.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/integration/operator/module/PluginInfo.java @@ -61,4 +61,14 @@ public class PluginInfo { public String getRunMode() { return runMode; } + + @Override + public String toString() { + return "PluginInfo{" + + "pluginDescriptor=" + pluginDescriptor + + ", pluginState=" + pluginState + + ", path='" + path + '\'' + + ", runMode='" + runMode + '\'' + + '}'; + } } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/realize/ConfigDefinitionTip.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/realize/ConfigDefinitionTip.java new file mode 100644 index 0000000000000000000000000000000000000000..681ce1eae2728f4963d2152b47eadf947aba8f04 --- /dev/null +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/realize/ConfigDefinitionTip.java @@ -0,0 +1,55 @@ +package com.gitee.starblues.realize; + +import com.gitee.starblues.factory.PluginRegistryInfo; +import com.gitee.starblues.integration.operator.module.PluginInfo; +import com.gitee.starblues.utils.SpringBeanUtils; +import org.pf4j.PluginManager; +import org.pf4j.PluginWrapper; +import org.springframework.context.ApplicationContext; + +/** + * 给系统中所有ConfigDefinition 提供一个小工具类。可通过它获取主程序的某些bean. 和当前插件一些信息 + * @author starBlues + * @version 2.4.2 + */ +public class ConfigDefinitionTip { + + private final PluginRegistryInfo pluginRegistryInfo; + + public ConfigDefinitionTip(PluginRegistryInfo pluginRegistryInfo) { + this.pluginRegistryInfo = pluginRegistryInfo; + } + + /** + * 得到当前插件信息 + * @return 插件信息 + */ + public PluginInfo getCurrentPluginInfo(){ + PluginWrapper pluginWrapper = pluginRegistryInfo.getPluginWrapper(); + PluginManager pluginManager = pluginWrapper.getPluginManager(); + return new PluginInfo(pluginWrapper.getDescriptor(), pluginWrapper.getPluginState(), + pluginWrapper.getPluginPath().toAbsolutePath().toString(), + pluginManager.getRuntimeMode().toString()); + } + + /** + * 得到主程序的 ApplicationContext + * @return ApplicationContext + */ + public ApplicationContext getMainApplication() { + return pluginRegistryInfo.getMainApplicationContext(); + } + + /** + * 获取当前插件的其他的ConfigDefinition + * @param configDefinitionClass ConfigDefinition的类类型 + * @param 类类型 + * @return T + */ + public T getOtherConfigDefinition(Class configDefinitionClass){ + return SpringBeanUtils.getObjectClass( + pluginRegistryInfo.getConfigSingletons(), + configDefinitionClass); + } + +} diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/ClassUtils.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/ClassUtils.java index 89c3d528a5e22850d7657fc4cc90c97a16b7c5b8..6d25abbf6d05132df65db82262e05ebf2b0dc790 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/ClassUtils.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/ClassUtils.java @@ -2,7 +2,14 @@ package com.gitee.starblues.utils; import org.springframework.util.ReflectionUtils; +import java.lang.annotation.Annotation; import java.lang.reflect.Field; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Proxy; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; /** * 类工具类 @@ -15,6 +22,15 @@ public class ClassUtils { } + public static List getAllFields(Class clazz) { + List fieldList = new ArrayList<>(); + while (clazz != null){ + fieldList.addAll(new ArrayList<>(Arrays.asList(clazz.getDeclaredFields()))); + clazz = clazz.getSuperclass(); + } + return fieldList; + } + /** * 通过反射获取字段 * @param o 对象 @@ -27,6 +43,7 @@ public class ClassUtils { if(o == null){ return null; } + Field templateResolversField = ReflectionUtils.findField(o.getClass(), fieldName); return getReflectionField(templateResolversField, o); @@ -69,4 +86,17 @@ public class ClassUtils { return (T) fieldObject; } + /** + * 得到注解修改者 + * @param annotation 注解 + * @return 修改者集合 + * @throws Exception 异常 + */ + public static Map getAnnotationsUpdater(Object annotation) throws Exception { + InvocationHandler invocationHandler = Proxy.getInvocationHandler(annotation); + Field field = invocationHandler.getClass().getDeclaredField("memberValues"); + field.setAccessible(true); + return (Map) field.get(invocationHandler); + } + } diff --git a/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/SpringBeanUtils.java b/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/SpringBeanUtils.java index e566c02bbcd2d705ab74c15bcaf830797f780c37..33d4fb5fa3813760c12fc1d442330d6d4ff1f3a8 100644 --- a/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/SpringBeanUtils.java +++ b/springboot-plugin-framework/src/main/java/com/gitee/starblues/utils/SpringBeanUtils.java @@ -48,6 +48,25 @@ public class SpringBeanUtils { return null; } + /** + * 获取具体类的对象 + * @param sourceObject 源对象集合 + * @param aClass 对象对应的类类型 + * @param 类实现 + * @return T + */ + public static T getObjectClass(Set sourceObject, Class aClass){ + if(sourceObject == null || sourceObject.isEmpty()){ + return null; + } + for (Object configSingletonObject : sourceObject) { + if(Objects.equals(configSingletonObject.getClass(), aClass)){ + return (T) configSingletonObject; + } + } + return null; + } + /** * 得到存在的bean, 不存在则返回null * @param applicationContext ApplicationContext容器