When does spring instantiate a bean

Source: Internet
Author: User

Provides a brief description of when spring instantiates a bean, starting with 2 scenarios
First: If you use Beanfactory as the factory class for the spring bean, all the beans are instantiated the first time the bean is used
Second: If you use ApplicationContext as the factory class for spring beans, you are divided into the following scenarios:
(1): If the bean's scope is singleton , and Lazy-init is False(the default is False, so you can not set), then The bean is instantiated when the ApplicationContext is started, and the instantiated bean is placed in a cache of the map structure, which is taken directly from the cache the next time the bean is used.
(2): If the bean's scope is singleton and Lazy-init is true, then instantiation of the bean is instantiated the first time the bean is used
(3): If the bean's scope is prototype , instantiation of the bean is instantiated the first time the bean is used

When does spring instantiate a bean

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.