蓟县网站建设,东营网站建设东营市南一路东营软件园英,wordpress 从新安装,wordpress标签列表内页无效链接Solon Plugin 是框架的核心接口#xff0c;简称“插件”。其本质是一个“生命周期”接口。它可让一个组件类参与程序的生命周期过程#xff08;这块看下#xff1a;《应用启动过程与完整生命周期》#xff09;#xff1a;
FunctionalInterface
public interface Plugin {…Solon Plugin 是框架的核心接口简称“插件”。其本质是一个“生命周期”接口。它可让一个组件类参与程序的生命周期过程这块看下《应用启动过程与完整生命周期》
FunctionalInterface
public interface Plugin {//启动void start(AopContext context) throws Throwable;//预停止default void prestop() throws Throwable{}//停止default void stop() throws Throwable{}
}目前对它的使用主要有两种方式
1、做为具有生命周期的组件使用
做为注解组件实例产生后会加入 SolonApp 实例的 plugins 列表并会执行 start 接口当程序停止时会触发 stop 接口。
这个方式一般是需要对一些有生命周期的对象进行管理比如通讯服务
Component
public class StompServerPlugin implements Plugin {Inject(${server.stopm.port})int port;StompServer server;Overridepublic void start(AopContext context) throws Throwable {server new StompServer(port);server.start();}Overridepublic void stop() throws Throwable {server.stop();}
}目前这个方式较少使用有大量的通讯服务或有生命周期对象已被封装成插件。如无必要也不建议使用。
2、做为一个模块生命周期的对接使用为框架或业务提供扩展能力
生态体系里的所有插件的封装都基于这个方式。也是最常使用的场景。
在这个方式里不能使用注解能力为了绝对的安全且需要使用配置文件申明插件为了获得更早的执行时机
public class XPluginImpl implements Plugin {Overridepublic void start(AopContext context) throws Throwable {//...}Overridepublic void stop() throws Throwable {}
}具体看一下《插件扩展机制Spi》。