when is a spring bean instantiated

后端 未结 7 1428
借酒劲吻你
借酒劲吻你 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:42

    Assuming the bean is a singleton, and isn't configured for lazy initialisation, then it's created when the context is started up. getBean() just fishes it out.

    Lazy-init beans will only be initialised when first referenced, but this is not the default. Scoped beans (e.g. prototype-scoped) will also only be created when first referenced.

提交回复
热议问题