Spring IOC Bean's scope attribute value: Prototype and Singleton

Source: Internet
Author: User

keyword: Spring IOC bean's scope attribute value: Prototype and Singleton

Spring IOC Bean's scope attribute value: Prototype and Singleton

If the specified bean is scoped to scope= "prototype" in <bean>, the bean is returned to the caller, who is responsible for the bean

Later life management, spring no longer manages the lifecycle of these beans. If the scope is set to Scope= "Singleton", the

The bean is placed into the cache pool of the spring IOC container, and the bean reference is returned to the caller, and spring continues to follow the bean

Management of life. The default property is Singleton

The bean exists in two forms: the Singletons form and the prototypes form. When a bean exists in singletons form, Beanfactory manages only one shared instance. All instance requests to this particular bean cause a reference to be returned for this unique bean instance.
When the bean is in prototype form, each instance request to the bean causes a new instance to be created. This is an ideal solution when users need objects that are not affected by other user objects or have similar requirements.
The bean defaults to exist in singleton form unless you explicitly specify it otherwise. Be careful that when you change the bean's setting to prototype mode, each instance request to the bean causes a new bean instance to be created, which may not be what you expect. So, you should only set the bean to prototype mode when you really need it

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.