说明JFinal-event 2.x 参考 Spring 4.2.x 中 Event 的使用方式而生,为 JFinal 用户带来更多方便。其核心目标是深层次解耦,为您节约更多时间,去陪恋人、家人和朋友 :)年初 @idoz 提议实现类似 Spring 4.2 里的 PayloadApplicationEvent,其实我早就有此想法,一直没有抽出时间来折腾。顺便在 码云上添加了 issues 3.0优化,有2点功能:第一点,实现 PayloadApplicationEvent 不难。扩展个 EventTypeclass1 为 ApplicationEvent 类 或者 PayloadApplicationEvent类信息class2 为 ApplicationEvent 泛型,或者 Payload 中的类信息第二点,将类扫描改为 annotation Processor 编译期处理(避免容器环境差异)由于 @EventListener 注解可以在任何方法中,annotation Processor 需要扫描 *,然后 找出 对应的含有 @EventListener 方法的类,然后写入 META-INF/dream.events 文件中。本次版本升级完成了第一点,第二点由于觉得更加适合底层框架去实现,从而方便扩展,对于 annotation Processor 感兴趣的朋友可以了解我的开源 mica-auto更新说明2019-04-08 v2.3.0升级到 jfinal 3.8。支持 @EventListener 方法可以无参数。ObjenesisBeanFactory 和 jfinal Aop inject 冲突,去掉对 JFinal inject 支持,标记为弃用。新增 SourceClass 作为 event 事件源(同 Spring PayloadApplicationEvent),event模型不再需要实现 ApplicationEvent。@EventListener 注解新增 value 变量,功能同 events。修复 @EventListener events 参数类型判断bug。初始化插件// 初始化插件EventPlugin plugin = new EventPlugin();// 设置为异步,默认同步,或者使用threadPool(ExecutorService executorService)自定义线程池。plugin.async();// 设置扫描jar包,默认不扫描plugin.scanJar();// 设置监听器默认包,多个包名使用;分割,默认全扫描plugin.scanPackage(“net.dreamlu”);// bean工厂,默认为DefaultBeanFactory,可实现IBeanFactory自定义扩展// 对于将@EventListener写在不含无参构造器的类需要使用ObjenesisBeanFactory(2.3.0 已经不推荐使用)plugin.beanFactory(new ObjenesisBeanFactory());// 手动启动插件,用于main方法启动,jfinal中不需要,添加插件即可。plugin.start();// 停止插件,用于main方法测试plugin.stop();新建事件类(任意模型即可 2.3.0支持)public class AccountEvent { private Integer id; private String name; private Integer age; // 省略 get set}编写监听@EventListenerpublic void listenTest1Event(AccountEvent event) { System.out.println(“AccountEvent:” + event);}发送事件AccountEvent event = new AccountEvent();event.setId(1);event.setName(“张三”);event.setAge(18);EventKit.post(event);@EventListener注解说明示例@EventListener(events = Test1Event.class, order = 1, async = true, condition = “event.isExec()")说明value 或 events支持的事件类型数组,用于将事件方法定义为ApplicationEvent或者自定义父类。public class Test { // Test1Event, Test2Event 为 TestEvent 子类 @EventListener({Test1Event.class, Test2Event.class}) public void applicationEvent(TestEvent event) { System.out.println(Thread.currentThread().getName() + “\tevent:” + event); }}order排序,数值越小越先执行,默认为Integer.MAX_VALUEasync异步执行,需要插件开启async()或者自定义线程池。condition表达式条件,使用event.xxxx,event.isExec() == true判定event的属性或者方法。jar依赖jar包下载http://central.maven.org/mave…以上版本均已上传到maven仓库~<dependency> <groupId>net.dreamlu</groupId> <artifactId>JFinal-event</artifactId> <version>2.3.0</version></dependency>开源推荐mica Spring boot 微服务核心组件集:https://gitee.com/596392912/micaAvue 一款基于vue可配置化的神奇框架:https://gitee.com/smallweigit/avuepig 宇宙最强微服务(架构师必备):https://gitee.com/log4j/pigSpringBlade 完整的线上解决方案(企业开发必备):https://gitee.com/smallc/SpringBladeIJPay 支付SDK让支付触手可及:https://gitee.com/javen205/IJPay关注我们扫描上面二维码,更多精彩内容每天推荐!