spring事件扩展

时间:2013-11-04 15:29:26
【文件属性】:
文件名称:spring事件扩展
文件大小:2KB
文件格式:RAR
更新时间:2013-11-04 15:29:26
spring事件扩展 /* 事件传播 ApplicationContext基于Observer模式(java.util包中有对应实现),提供了针对Bean的事件传 播功能。通过Application. publishEvent方法,我们可以将事件通知系统内所有的 ApplicationListener。 事件传播的一个典型应用是,当Bean中的操作发生异常(如数据库连接失败),则通过事件传播 机制通知异常监听器进行处理。在笔者的一个项目中,就曾经借助事件机制,较好的实现了当系统 异常时在监视终端上报警,同时发送报警SMS至管理员手机的功能。 */ public class LoginAction implements ApplicationContextAware { private ApplicationContext applicationContext; public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { this.applicationContext = applicationContext; } public int login(String username, String password) { ActionEvent event = new ActionEvent(username); this.applicationContext.publishEvent(event); ActionType _event = new ActionType(username); this.applicationContext.publishEvent(_event); ActionUserInfo __event = new ActionUserInfo(username); this.applicationContext.publishEvent(__event); return 0; }
【文件预览】:
LoginAction.java
ActionListener.java
ActionType.java
ActionEvent.java
applicationContext.xml
ActionUserInfo.java

网友评论