工作中需要对一个原本加载属性文件的工具类修改成对数据库的操作当然,ado层已经写好,但是需要从Spring中获取bean,然而,工具类并没有交给Spring来管理,所以需要通过方法获取所需要的bean.于是整理了Spring获取bean的几种方法. 一. 在初始化时保存ApplicationContext对象 ApplicationContext ac = new FileSystemXmlApplicationContext("classpath:beans.xml"); ac.ge
参考文章 Introduction to the Spring IoC container and beans BeanFactory 和ApplicationContext(Bean工厂和应用上下文) Spring ApplicationContext - Resource leak: 'context' is never closed 版本说明 JDK 1.7 Spring3.2.14 <dependency> <groupId>org.springframework</