231k views
3 votes
Are beans loaded eagerly or lazily within the ApplicationContext? How can you change this?

1 Answer

5 votes

Final answer:

By default, beans in the ApplicationContext are loaded eagerly. To change this to lazy loading, you can use the 'lazy-init' attribute in the bean's configuration.

Step-by-step explanation:

By default, beans in the ApplicationContext are loaded eagerly.

Eager loading means that all the beans are created up front when the ApplicationContext starts. This can result in a longer startup time and greater memory usage if there are many beans defined.

To change this to lazy loading, you can use the 'lazy-init' attribute in the bean's configuration. Setting 'lazy-init' to 'true' will delay the creation of the bean until it is actually needed.

User JaAnTr
by
8.5k points