By default, the container creates and configures all singleton beans during initialization
. To avoid this, we can use the lazy-init attribute with value true on the bean configuration:
<bean id="item1" class="org.baeldung.store.ItemImpl1" lazy-init="true" />
Consequently, the item1 bean will only be initialized when it's first requested
, and not at startup. The advantage of this is faster
initialization time, but the trade-off is that we won't discover
any configuration errors until after the bean is requested, which could be several hours or even days after the application has already been running.
参考:
Intro to Inversion of Control and Dependency Injection with Spring