同步操作将从 如梦技术/JFinal-event 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
A short and simple permissive license with conditions only requiring preservation of copyright and license notices. Licensed works, modifications, and larger works may be distributed under different terms and without source code.
模仿的Spring中的消息事件:详解Spring事件驱动模型
专为JFinal设计,无任何第三方依赖,小巧玲珑。
JFinal-event
插件,老版本
使用请查看文档 wiki
// 初始化插件
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();
public class AccountEvent {
private Integer id;
private String name;
private Integer age;
// 省略 get set
}
@EventListener
public 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(events = Test1Event.class, order = 1, async = true, condition = "event.isExec()")
value
或events
支持的事件类型数组,用于将事件方法定义为ApplicationEvent
或者自定义父类。
public class Test {
@EventListener({Test1Event.class, Test2Event.class})
public void applicationEvent(ApplicationEvent event) {
String xx = (String) event.getSource();
System.out.println(Thread.currentThread().getName() + "\tsource:" + xx);
}
}
order
排序,数值越小越先执行,默认为Integer.MAX_VALUE
async
异步执行,需要插件开启async()
或者自定义线程池。
condition
表达式条件,使用event.xxxx,event.isExec() == true
判定event的属性或者方法。
jar包下载 http://central.maven.org/maven2/net/dreamlu/JFinal-event/
以上版本均已上传到maven仓库~
<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>JFinal-event</artifactId>
<version>2.3.0</version>
</dependency>
欢迎拍砖~~~
( The MIT License )
mica
Spring boot 微服务核心组件集:https://gitee.com/596392912/mica
Avue
一款基于vue可配置化的神奇框架:https://gitee.com/smallweigit/avue
pig
宇宙最强微服务(架构师必备):https://gitee.com/log4j/pig
SpringBlade
完整的线上解决方案(企业开发必备):https://gitee.com/smallc/SpringBlade
IJPay
支付SDK让支付触手可及:https://gitee.com/javen205/IJPay
精彩内容每日推荐!!
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。