我们经常说IOC容器,它具体由谁来充当这个角色呢,我的理解ApplicationContext是用来管理IOC容器中的Bean的,IOC容器本质上是由DefaultListableBeanFactory担当的。
我们想从容器中获得某个Bean,是通过ApplicationContext来获取的,实际实现是从容器DefaultListableBeanFactory取的,比如下面这样:
public class BeanExample {
public static void main(String[] args) {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");//创建bean
UserService userService = (UserService) applicationContext.getBean("userService");//获取bean
userService.hello("haha");
}
}
<bean id="userService" class="com.hand.user.dal.UserServiceImpl" scope="prototype"/> <!--指定实例化类型为原型-->
<bean id="studentService&#