when is a spring bean instantiated

后端 未结 7 1411
借酒劲吻你
借酒劲吻你 2020-12-08 07:26
ApplicationContext ctx = new ClassPathXmlApplicationContext(
    \"com/springinaction/springidol/spring-idol.xml\");
Performer performer = (Performer) ctx.getBean(\"         


        
7条回答
  •  轮回少年
    2020-12-08 07:48

    It depends what is the scope of the bean you are calling with getBean() method. If it is 'Singleton', it is pre-instantiated by the ApplicationContext.

    If you are using BeanFactory as an IOC Container, then it uses lazy initialization and the beans will be instantiated only when you call the getBean() method.

    This is an advantage of ApplicationContext over BeanFactory that it solves Circular Dependency problem.

提交回复
热议问题