Spring Bean configuration defaults to Single instance Pring Bean life cycle

Source: Internet
Author: User

Reference: http://hi.baidu.com/victorlin23/blog/item/45ba7d1b2ccbced8ad6e7595.html

The bean defaults to a single example.

If you do not want a single example, you need the following configuration:
<bean id= "user" class= "..." singleton= "false"/>

Singleton is to configure whether the bean is a single case, and if not, the default value is true.

Annotations:

Spring Bean life cycle

The scope of the 1.Bean can be set through the scope property of the bean label, and the scope of the bean includes:
By default scope= "Singleton", the Bean is a singleton, and anyone who gets the bean instance is the same instance;
Scope= "Prototype", any one instance is a new instance;
Scope= "Request", in a Web application, each instance is scoped to the request;
Scope= "Session", in the Web application, the scope of each instance is the session range;

Note: By default, the bean instance is instantiated when it is initialized by the spring container, and the constructor method without parameters is invoked by default. In other cases, the bean will be instantiated when it gets the instance.

2.Bean You can specify a method to execute after initialization by specifying a property Init-method, and a method to execute when the property Destroy-method is destroyed.

Syntax: <bean ... destroy-method= "method name called on Destroy" init-method= "method name executed after initialization"/>

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.