Java records Two modes of the-SPRINGMVC scope property

Source: Internet
Author: User

Singleton scope: When a bean definition is set to singleton scope, only one shared bean instance exists in the Spring IOC container, and all of the Bean's
request, as long as the ID matches the bean definition, only the same instance of the bean is returned. It is worth emphasizing that the singleton scope is the default scope in spring.
prototype scope:prototype-scoped beans cause each request to the bean to be injected into another bean, or to invoke the container's Getbean programmatically
() method) will create a new bean instance. Based on experience, you should use the prototype scope for stateful beans, while for stateless beans you should use the Singleton action
domain.
for beans with prototype scope, it is important to note that spring cannot be responsible for the entire life cycle of the bean. A bean with a prototype scope is created and handed
The user is responsible for destroying the object recycling resources.
to put it simply:
Singleton has only one instance, which is a singleton mode. (default)
prototype Access creates one instance at a time, equivalent to new.
Application:
1. The need to reclaim important resources (database connections, etc.) is configured as Singleton, and if configured for prototype requires an application to ensure that resources are properly reclaimed.
2. Stateful beans configured as Singleton will cause unknown problems and can be considered configured as prototype.

Java records Two modes of the-SPRINGMVC scope property

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.