我是靠谱客的博主 大方星月,这篇文章主要介绍spring-code详解1.实例化beanFactory ,现在分享给大家,希望可以做个参考。

spring code 为spring容器的核心。 有beans,beanFactory,beandefinitions,applicationContext等定义。实现了控制反转与依赖注入bean配置以及加载。

1.实例化beanFactory

1.1 加载classPath下的配置文件

ClassPathResource context = new ClassPathResource("applicationContext.xml");

XmlBeanFactory factory = new XmlBeanFactory(context);

Iservice service = factory.getBean("service");

1.2使用文件流加载任意位置的文件

InputStream in = new FileInputStream("c:\ApplicationContext.xml");

XmlBeanFactory factory = new XmlBeanFactory(in);

1.3使用classPathXMLApplicationContext加载多个配置文件

ClassPathXMLApplicationContext context  = new ClassPathXMLApplicationContext(new String[]{"ApplicationContext.xml","ApplicationContext-part2.xml"})
BeanFactory Factory = (BeanFactory)context;

最后

以上就是大方星月最近收集整理的关于spring-code详解1.实例化beanFactory 的全部内容,更多相关spring-code详解1.实例化beanFactory内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(50)

评论列表共有 0 条评论

立即
投稿
返回
顶部