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);
}
}
[] [] [] []