when is a spring bean instantiated

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


        
相关标签:
7条回答
  • 2020-12-08 08:02
    1. By default, all beans are singletons, so whenever Application context gets created, they are all pre-loaded. If, specifically, any singleton bean has an attribute lazy-init="true" set, it will be lazy-loaded, i.e. it will be instantiated when the getBean method is called for the first time.

    2. For other scopes, beans will be instantiated whenever they are requested.

    0 讨论(0)
提交回复
热议问题