`
prodream
  • 浏览: 106167 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

ApplicationContextAware

JDK 
阅读更多

JDK-doc 2.5.6

Interface ApplicationContextAware

 

Interface to be implemented by any object that wishes to be notified of the ApplicationContext that it runs in.

 

method:

/*

*  Set the ApplicationContext that this object runs in.

*/

void setApplicationContext(ApplicationContext applicationContext) 

 

 

实现了这个接口的类将告诉application:我需要你提供给我ApplicationContext实例.

 

public class UserService implements ApplicatonContextAware{

 

private static UserService instance;

private static ApplicationContext appContext;

 

final public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
    //System.out.println("BeanAware.setApplicationContext("+getClass().getName()+")");
      Map beans = applicationContext.getBeansOfType(getClass());
      instance=((UserService) beans.values().iterator().next());

      this.appContext = applicationContext;
   }

 public static UserService getInstance(){

       return instance;

 }

}//end class

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics