java

位置:IT落伍者 >> java >> 浏览文章

Spring中事件处理的小技巧[3]


发布日期:2019年11月25日
 
Spring中事件处理的小技巧[3]

java 代码

import orgspringframeworkbeansBeansException;

import orgspringframeworkcontextApplicationContext;

import orgspringframeworkcontextApplicationContextAware;

import orgspringframeworkcontextsupportFileSystemXmlApplicationContext;

public class Publisher implements ApplicationContextAware {

private ApplicationContext context;

@Override

public void setApplicationContext(ApplicationContext arg)

throws BeansException {

// TODO Autogenerated method stub

thiscontext = arg;

}

public void publish(String message){

contextpublishEvent(new MessageEvent(thismessage));

}

public static void main(String[] args) {

ApplicationContext ctx = new FileSystemXmlApplicationContext (src/applicationContextxml);

Publisher pub = (Publisher) ctxgetBean(publisher);

pubpublish(Hello World!);

pubpublish(The quick brown fox jumped over the lazy dog);

}

}

[] [] [] []

               

上一篇:Spring中事件处理的小技巧[4]

下一篇:Spring中事件处理的小技巧[2]