Bean management by spring

Source: Internet
Author: User
1. In spring, bean is Singleton in singleton mode by default. The default value is lazy-load.

2. During lazy-load, the Bean factory will load the definition information, but it will only instantiate it when explicitly calling it. When a quartz timer task is configured in spring, the following configuration is used: the "sfactory" display is not specified as loading immediately at the beginning, causing the task to fail to run. <? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype beans public "-// spring // DTD bean // en" "http://www.springframework.org/dtd/spring-beans.dtd">
<Beans default-Lazy-init = "true">

<! -- Spring scheduling factory -->
<Bean id = "sfactory"
Class = "org. springframework. Scheduling. Quartz. schedulerfactorybean"
Singleton = "true" lazy-init = "false">
<Property name = "triggers">
<List>
<Ref local = "crontrigger"/>
</List>
</Property>
</Bean>

<! -- Trigger triggered by spring -->
<Bean id = "crontrigger"
Class = "org. springframework. Scheduling. Quartz. crontriggerbean">
<Property name = "jobdetail">
<Ref bean = "examplejob"/>
</Property>
<Property name = "cronexpression">
<! -- Run every morning at 6 am -->
<Value> 0 0 03 **? </Value>
</Property>
</Bean>


<! -- Task implementation class -->
<Bean name = "examplejob"
Class = "org. springframework. Scheduling. Quartz. jobdetailbean">
<Property name = "jobclass">
<Value> com. decentsoft. smmail. Mail. task. trashcatalogcleartask </value>
</Property>
<Property name = "jobdataasmap">
<Map>
<Entry key = "mailoperationservice">
<Ref bean = "mailoperationservice"> </Ref>
</Entry>
</Map>
</Property>
</Bean>


</Beans>

3. Bean loading process:
1) The container looks for bean definition information and instantiates it.
2) using dependency injection, spring configures all bean attributes according to bean definition information.
3) if the beannameaware interface is implemented, the factory will call the setbeanname () of bean to the bean ID
4) if the beanfactoryaware interface is implemented, the factory calls the setbeanfactory () method to pass it to the factory itself.
5) If beanpostprocessor is associated with bean, their postprocessbeforeinitialation () will be called.
6) if the bean specifies the init-method, it will be called.
7) If beanpostprocessor is associated with bean, their postprocessafterinitialation () will be called.

Bean destruction:
1) The disposablebean interface can be implemented.
2) Specify the custom destroy Method When configuring bean.

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.