在代码中获取spring ApplicationContext
代码:
- import org.springframework.beans.Bean***ception;
- import org.springframework.context.ApplicationContext;
- import org.springframework.context.ApplicationContextAware;
- public final class SpringHelper implements ApplicationContextAware {
- private static ApplicationContext context = null;
- @Override
- public void setApplicationContext(ApplicationContext arg0)
- throws Bean***ception {
- context = arg0;
- }
- public static Object getBean(String beanName){
- return context.getBean(beanName);
- }
- }
阅读(1168) | 评论(0) | 转发(0) |