【功能修改】IoT:更新问候语打印方法,返回问候语数量;删除不再使用的插件控制器和配置类

This commit is contained in:
安浩浩 2024-12-16 18:43:08 +08:00
parent 290fcd94d5
commit ce49123043
5 changed files with 6 additions and 76 deletions

View File

@ -30,11 +30,12 @@ public class Greetings {
@Autowired
private List<Greeting> greetings;
public void printGreetings() {
public Integer printGreetings() {
System.out.printf("找到扩展点的 %d 个扩展 '%s'%n", greetings.size(), Greeting.class.getName());
for (Greeting greeting : greetings) {
System.out.println(">>> " + greeting.getGreeting());
}
return greetings.size();
}
}
}

View File

@ -123,12 +123,12 @@ public class PluginController {
/**
* 打印问候语
*
* @return 1
* @return 问候语数量
*/
@PermitAll
@GetMapping("/printGreetings")
public ResponseEntity<Integer> printGreetings() {
greetings.printGreetings();
return ResponseEntity.ok(1);
Integer count = greetings.printGreetings();
return ResponseEntity.ok(count);
}
}

View File

@ -1,22 +0,0 @@
package cn.iocoder.yudao.module.iot.plugin;
import org.pf4j.Extension;
import org.pf4j.ExtensionPoint;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/iot/plugin-demo")
@Extension
public class IoTHttpPluginController implements ExtensionPoint {
@GetMapping("/greet")
public String greet() {
return "Hello from MyPlugin!";
}
@PostMapping("/message")
public void receiveMessage(@RequestBody String message) {
System.out.println("Received message: " + message);
}
}

View File

@ -1,33 +0,0 @@
package cn.iocoder.yudao.module.iot.plugin;
import org.pf4j.PluginWrapper;
import org.pf4j.spring.SpringPlugin;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
public class IoTPlugin extends SpringPlugin {
public IoTPlugin(PluginWrapper wrapper) {
super(wrapper);
}
@Override
public void start() {
System.out.println("IoTPlugin 启动");
}
@Override
public void stop() {
System.out.println("IoTPlugin 停止");
super.stop(); // to close applicationContext
}
@Override
protected ApplicationContext createApplicationContext() {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.setClassLoader(getWrapper().getPluginClassLoader());
applicationContext.register(IoTHttpPluginController.class); // 注册 IoTPluginConfig
applicationContext.refresh();
System.out.println("IoTPlugin 加载完成");
return applicationContext;
}
}

View File

@ -1,16 +0,0 @@
package cn.iocoder.yudao.module.iot.plugin;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.boot.web.server.WebServerFactoryCustomizer;
import org.springframework.boot.web.server.ConfigurableWebServerFactory;
import org.springframework.context.annotation.Bean;
@Configuration
public class IoTPluginConfig {
@Bean
public IoTHttpPluginController ioTHttpPluginController() {
return new IoTHttpPluginController();
}
}