Spring框架下获取Bean的几种方式

Posted by 萝卜

 

通过xml配置文件

bean配置在xml里面,spring提供多种方式读取配置文件得到ApplicationContext.

第一种方式:FileSystemXmlApplicationContext

通过程序在初始化的时候,导入Bean配置文件,然后得到Bean实例: ApplicationContext ac = new FileSystemXmlApplicationContext("applicationContext.xml") ac.getBean("beanName");

标签:Spring, 框架, 获取, Bean, 方式, pring