Bean configuration parameters in spring

Source: Internet
Author: User

1. ID: the unique ID of JavaBean in beanfactory. this parameter is required as the index name when obtaining a JavaBean instance through beanfactory in the code.

2. Class: name of the JavaBean class

3. Singleton: Specifies whether the Java Bean uses the singleton mode. If it is set to "true", only one Java Bean instance is maintained within the scope of beanfactory, the Code obtains the reference of this JavaBean instance through beanfactory. If this parameter is set to "false", beanfactory returns a new instance every time it obtains the JavaBean instance through beanfactory.

4. init-method: initialization method. This method will be executed after beanfactory creates a JavaBean instance and before returning a reference to the application layer. It is generally used for initialization of some resources.

5. destruction method. This method will be executed when beanfactory is destroyed and is generally used for resource release.

6. Depends-on: bean dependency. Generally, this parameter is not required. Spring organizes the construction of various dependencies based on the situation (here
The depends-on attribute in the example is not required ). In some special cases, for example, some static variables in JavaBean need to be initialized (this is a bad smell and should be avoided in design ). You can use depends-on to specify its dependency to ensure that the resources specified by depends-on are loaded before the bean is loaded.

7. <value>: You can specify the attribute value through the <value/> node. Beanfactory will automatically match according to the attribute type corresponding to Java Bean. Note: <value> </value> indicates an empty string. To set the attribute value to null, you must use the <null/> node.

8. <ref> specifies the reference relationship between attributes and other beans in beanfactory.

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.