熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java開源技術 >> 正文

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

2022-06-13   來源: Java開源技術 

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

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/Java/ky/201311/29121.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.