`

SpringBeanFactory

XML 
阅读更多
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);
    }
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics