Chinaunix首页 | 论坛 | 博客
  • 博客访问: 334871
  • 博文数量: 117
  • 博客积分: 650
  • 博客等级: 中士
  • 技术积分: 738
  • 用 户 组: 普通用户
  • 注册时间: 2010-09-21 13:07
文章分类

全部博文(117)

文章存档

2014年(2)

2013年(2)

2012年(112)

2010年(1)

分类: Java

2012-08-31 17:22:04

在代码中获取spring ApplicationContext  


代码:


点击(此处)折叠或打开

  1. import org.springframework.beans.Bean***ception;
  2. import org.springframework.context.ApplicationContext;
  3. import org.springframework.context.ApplicationContextAware;

  4. public final class SpringHelper implements ApplicationContextAware {
  5.     private static ApplicationContext context = null;

  6.     @Override
  7.     public void setApplicationContext(ApplicationContext arg0)
  8.             throws Bean***ception {
  9.         context = arg0;
  10.     }

  11.     public static Object getBean(String beanName){
  12.         return context.getBean(beanName);
  13.     }

  14. }

阅读(1144) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~