Lazy Initialized Beans

Revision as of 03:57, 3 June 2018 by Rasimsen (talk | contribs) (Created page with "By default, the container creates and configures all singleton beans during initialization. To avoid this, you can use the lazy-init attribute with value true on the bean conf...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

By default, the container creates and configures all singleton beans during initialization. To avoid this, you can use the lazy-init attribute with value true on the bean configuration:

<bean id="item1" class="org.baeldung.store.ItemImpl1" lazy-init="true" />

As a consequence, the item1 bean will be initialized only when it’s first requested, and not at startup. The advantage of this is faster initialization time, but the trade-off is that configuration errors may be discovered only after the bean is requested, which could be several hours or even days after the application has already been running.