Springbean of Technical Summary

Source: Internet
Author: User

1) Application context in springbeanfactory

Beanfactory interface, the common implementation class is: Xmlbeanfactory.

ApplicationContext

The ApplicationContext interface, which inherits the Beanfactory interface, is more commonly used.

Among the more commonly used implementations are:

Classpathxmlapplicationcontext

Filesystemxmlapplicationcontext

Xmlwebapplicationcontext

Webapplicationcontext

The interface inherits from ApplicationContext and is applied to spring's web environment.


2) Several special bean interfaces in spring

A) Beanfactoryaware interface, let the bean get the spring container.

b) Applicationcontextaware interface, the role of ibid.

c) Beannameaware interface to get the ID of the bean itself.

d) Initializingbean interface, dependent upon injected behavior.

e) Disposablebean interface, the behavior of the bean before it is destroyed.

If a bean implements all of the above interfaces, it is configured as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/53/71/wKioL1RnfZ_QSec4AAB1M72XaQ4921.jpg "title=" Spring01.png "alt=" Wkiol1rnfz_qsec4aab1m72xaq4921.jpg "/>

From the bean initialization to the destruction process, the method is executed as follows:

    1. Construction method

    2. Method of Beannameaware interface

    3. Method of Beanfactoryaware interface

    4. Method of Applicationcontextaware interface

    5. Method of Initializingbean interface

    6. Init () method

    7. Disposablebean interface method

    8. Close () method


3) ApplicationContext event mechanism

If there is a applicationlistenerbean in the container (the bean that implements the Applicationlistener interface), The Applicatioinlistener bean is automatically triggered whenever ApplicationContext publishes Applicationevent (the published Bean needs to inherit the Applicationevent Class).


4) Spring get beanfactory

A) Implement the Beanfactoryaware interface.

b) obtained through Beanfactorylocator, the code is as follows:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/53/71/wKioL1Rnf1mQ8SN3AAHsFp6AoYc887.jpg "title=" Spring03.png "alt=" wkiol1rnf1mq8sn3aahsfp6aoyc887.jpg "/> parameter description: Beanfactorylocator for the XML file that needs to be loaded, if empty, Spring automatically searches for the Beanrefcontext.xml file under the Classpath, in the following format:

650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/53/73/wKiom1RnfwaDrDw_AAGeCzblJP4239.jpg "title=" Spring04.png "alt=" wkiom1rnfwadrdw_aageczbljp4239.jpg "/> parameter beanfactorylocatorkey is the ID in the search file, for example beanfactorylocatorkey= "AAA".


5) Instantiation Time of Springbean

A) By default, the Bean in spring is a singleton and is instantiated when the container starts.

b) If the Bean in spring is configured as prototype, it is initialized when the bean is fetched. Thereafter, the bean will not be managed by the spring container as a normal object that is recycled by the Java virtual machine after it is exhausted.

c) If, by default, the Bean is set to lazy-init= "true", it is instantiated on the first use.

This article is from the "Doctoryang" blog, make sure to keep this source http://ybchina.blog.51cto.com/8888456/1577054

Springbean of Technical Summary

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.