我在用户登录后需要记录一下登录日志,安装JFinal-event的文档分别写好了LoginLogEvent及LoginLogListener类,但是在系统启动的时候,控制台会显示Listener is empty! Please check it!,然后事件并没有执行。
报错信息:
六月 06, 2016 1:26:10 下午 net.dreamlu.utils.ClassUtil warn 警告: Listener is empty! Please check it! 六月 06, 2016 1:26:10 下午 net.dreamlu.utils.ClassUtil warn 警告: Listener is empty! Please check @Listener is right?
//添加事件触发插件 EventPlugin eventPlugin = new EventPlugin(); //开启全局异步 eventPlugin.async(); //设置扫描jar包 eventPlugin.scanJar(); //设置监听器默认包 eventPlugin.scanPackage("com.apos"); me.add(eventPlugin);
代码如下:
@Listener(order=1,enableAsync=true) public class LoginLogListener implements ApplicationListener<LoginLogEvent> { @Override public void onApplicationEvent(LoginLogEvent event) { // TODO Auto-generated method stub UserInfo user=(UserInfo) event.getSource(); UserLoginLog loginLog = new UserLoginLog(); loginLog.setUid(user.getUid()); loginLog.setStoreCode(user.getStoreCode()); loginLog.set("loginDateTime", DateTools.getNowDateTime()); loginLog.save(); System.out.println(Thread.currentThread().getName()+"\tsource:"+event.getSource()); } }
public class LoginLogEvent extends ApplicationEvent { public LoginLogEvent(Object source) { super(source); // TODO Auto-generated constructor stub } /** * */ private static final long serialVersionUID = 1282453213041286427L; }