码迷,mamicode.com
首页 > 编程语言 > 详细

获得Spring容器

时间:2014-08-13 10:23:45      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   ar   div   log   new   

1. WebApplicationContext wac = ContextLoader.getCurrentWebApplicationCon; 

2. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext();

3.

    public class Springfactory implements BeanFactoryAware {  
      
        private static BeanFactory beanFactory;  
      
        // private static ApplicationContext context;  
      
        public void setBeanFactory(BeanFactory factory) throws BeansException {  
            this.beanFactory = factory;  
        }  
      
        /** 
         * 根据beanName名字取得bean 
         *  
         * @param beanName 
         * @return 
         */  
        public static <T> T getBean(String beanName) {  
            if (null != beanFactory) {  
                return (T) beanFactory.getBean(beanName);  
            }  
            return null;  
        }  
      
    }  

 

获得Spring容器,布布扣,bubuko.com

获得Spring容器

标签:style   blog   color   io   ar   div   log   new   

原文地址:http://www.cnblogs.com/dingyingsi/p/3909194.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!