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

通过类名获取spring里的Bean

时间:2016-05-29 16:41:37      阅读:269      评论:0      收藏:0      [点我收藏+]

标签:

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;

public class GetBeanFactory implements BeanFactoryAware  {
    private static BeanFactory beanFactory;  
    
    public static Object getSpringEntry(String beanId){
          return beanFactory.getBean(beanId);  
    }
    public static <T>T getSpringEntry(String beanId,Class<T>clazz){
        return clazz.cast(getSpringEntry(beanId));  
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        GetBeanFactory.beanFactory = beanFactory;  
        
    } 

}

 

通过类名获取spring里的Bean

标签:

原文地址:http://www.cnblogs.com/tietazhan/p/5539583.html

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