Commit a85890d958417e90564fe4ab075fdf6216cd1c9f

Authored by 安浩浩
1 parent 55243245

【功能完善】IoT: 添加插件目录配置,重构 SpringPluginManager 实例化逻辑,删除不再使用的 ExampleService 类以优化代码结构。

yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/framework/plugin/UnifiedConfiguration.java
... ... @@ -5,11 +5,13 @@ import cn.iocoder.yudao.module.iot.api.device.DeviceDataApi;
5 5 import cn.iocoder.yudao.module.iot.framework.plugin.listener.CustomPluginStateListener;
6 6 import lombok.extern.slf4j.Slf4j;
7 7 import org.pf4j.spring.SpringPluginManager;
  8 +import org.springframework.beans.factory.annotation.Value;
8 9 import org.springframework.context.annotation.Bean;
9 10 import org.springframework.context.annotation.Configuration;
10 11 import org.springframework.context.annotation.DependsOn;
11 12  
12 13 import javax.annotation.Resource;
  14 +import java.nio.file.Paths;
13 15  
14 16 @Slf4j
15 17 @Configuration
... ... @@ -19,6 +21,8 @@ public class UnifiedConfiguration {
19 21  
20 22 @Resource
21 23 private DeviceDataApi deviceDataApi;
  24 + @Value("${pf4j.pluginsDir:pluginsDir}")
  25 + private String pluginsDir;
22 26  
23 27 @Bean(SERVICE_REGISTRY_INITIALIZED_MARKER)
24 28 public Object serviceRegistryInitializedMarker() {
... ... @@ -31,7 +35,7 @@ public class UnifiedConfiguration {
31 35 @DependsOn(SERVICE_REGISTRY_INITIALIZED_MARKER)
32 36 public SpringPluginManager pluginManager() {
33 37 log.info("[init][实例化 SpringPluginManager]");
34   - SpringPluginManager springPluginManager = new SpringPluginManager() {
  38 + SpringPluginManager springPluginManager = new SpringPluginManager(Paths.get(pluginsDir)) {
35 39 @Override
36 40 public void startPlugins() {
37 41 // 禁用插件启动,避免插件启动时,启动所有插件
... ...
yudao-module-iot/yudao-module-iot-biz/src/main/java/cn/iocoder/yudao/module/iot/service/plugin/ExampleService.java deleted
1   -package cn.iocoder.yudao.module.iot.service.plugin;
2   -
3   -import cn.iocoder.yudao.module.iot.mqttrpc.server.RpcServer;
4   -import lombok.RequiredArgsConstructor;
5   -import org.springframework.stereotype.Service;
6   -
7   -import javax.annotation.PostConstruct;
8   -
9   -@Service
10   -@RequiredArgsConstructor
11   -public class ExampleService {
12   -
13   - private final RpcServer rpcServer;
14   -
15   - @PostConstruct
16   - public void registerMethods() {
17   - rpcServer.registerMethod("add", params -> {
18   - if (params.length != 2) {
19   - throw new IllegalArgumentException("add方法需要两个参数");
20   - }
21   - int a = ((Number) params[0]).intValue();
22   - int b = ((Number) params[1]).intValue();
23   - return add(a, b);
24   - });
25   -
26   - rpcServer.registerMethod("concat", params -> {
27   - if (params.length != 2) {
28   - throw new IllegalArgumentException("concat方法需要两个参数");
29   - }
30   - String str1 = params[0].toString();
31   - String str2 = params[1].toString();
32   - return concat(str1, str2);
33   - });
34   - }
35   -
36   - private int add(int a, int b) {
37   - return a + b;
38   - }
39   -
40   - private String concat(String a, String b) {
41   - return a + b;
42   - }
43   -}
44 0 \ No newline at end of file