打印本文 关闭窗口 |
|
| Spring中事件处理的小技巧 | |
| 作者:佚名 文章来源:不详 点击数 更新时间:2008/1/11 16:40:09 文章录入:杜斌 责任编辑:杜斌 | |
|
|
|
|
Spring事件处理一般过程: ·定义Event类,继承org.springframework.context.ApplicationEvent. ·编写发布事件类Publisher,实现org.springframework.context.ApplicationContextAware接口. ·覆盖方法setApplicationContext(ApplicationContext applicationContext)和发布方法publish(Object obj) ·定义时间监听类EventListener,实现ApplicationListener接口,实现方法onApplicationEvent(ApplicationEvent event). java 代码 import org.springframework.context.ApplicationEvent; /** * 定义事件信息 * @author new * */ public class MessageEvent extends ApplicationEvent { private String message; public void setMessage(String message){ this.message = message; } public String getMessage(){ return message; } public MessageEvent(Object source, String message) { super(source); this.message = message; // TODO Auto-generated constructor stub } private static final long serialVersionUID = 1L; } |
|
打印本文 关闭窗口 |