【功能修改】IoT:更新问候语打印方法,返回问候语数量;删除不再使用的插件控制器和配置类
This commit is contained in:
parent
290fcd94d5
commit
ce49123043
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue