SpringBeanFactory

SpringBeanFactory

import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.support.GenericApplicationContext;

public class SpringBeanFactory {
    private static GenericApplicationContext context;

    static {
        if (context == null) {
            context = new GenericApplicationContext();
            new XmlBeanDefinitionReader(context)
                    .loadBeanDefinitions(new String[] { "applicationContext*.xml" });
            context.refresh();
        }
    }

    private SpringBeanFactory() {
    }

    public static final Object getBean(String beanName) {
        return context.getBean(beanName);
    }
}
posted @ 2008-10-29 17:38  Earl_86  阅读(184)  评论(0编辑  收藏  举报