Spring applicationcontext Container Instantiation of Source notes refresh03

Source: Internet
Author: User

The previous two articles have written the Refresh method

Configurablelistablebeanfactory beanfactory = obtainfreshbeanfactory();

Loads the configured class into memory based on the configuration file (bean definition) and returns the default Beanfactory (org.springframework.beans.factory.support.DefaultListableBeanFactory) instance

Next is

    // Prepare The Bean Factory for use with this context.    Preparebeanfactory (beanfactory);

This is primarily a set of some of the properties that spring needs to use at run time

Specific code

protected voidpreparebeanfactory (configurablelistablebeanfactory beanfactory) {//Tell the internal beans factory to use the context ' s class loader etc.Beanfactory.setbeanclassloader (getClassLoader ()); Beanfactory.setbeanexpressionresolver (Newstandardbeanexpressionresolver ()); Beanfactory.addpropertyeditorregistrar (NewResourceeditorregistrar ( This)); //Configure The Bean Factory with context callbacks.Beanfactory.addbeanpostprocessor (NewApplicationcontextawareprocessor ( This)); Beanfactory.ignoredependencyinterface (Resourceloaderaware.class); Beanfactory.ignoredependencyinterface (Applicationeventpublisheraware.class); Beanfactory.ignoredependencyinterface (Messagesourceaware.class); Beanfactory.ignoredependencyinterface (Applicationcontextaware.class); //Beanfactory Interface not registered as resolvable type in a plain factory. //Messagesource registered (and found for autowiring) as a bean.Beanfactory.registerresolvabledependency (beanfactory.class, beanfactory); Beanfactory.registerresolvabledependency (Resourceloader.class, This); Beanfactory.registerresolvabledependency (Applicationeventpublisher.class, This); Beanfactory.registerresolvabledependency (ApplicationContext.class, This); //Detect a loadtimeweaver and prepare for weaving, if found.        if(Beanfactory.containsbean (load_time_weaver_bean_name)) {Beanfactory.addbeanpostprocessor (Newloadtimeweaverawareprocessor (beanfactory)); //Set A temporary ClassLoader for type matching.Beanfactory.settempclassloader (NewContexttypematchclassloader (Beanfactory.getbeanclassloader ())); }        //Register default environment beans.        if(!Beanfactory.containsbean (System_properties_bean_name))            {Map systemproperties; Try{systemproperties=system.getproperties (); }            Catch(Accesscontrolexception ex) {systemproperties=NewReadonlysystemattributesmap () {@Overrideprotectedstring Getsystemattribute (String propertyname) {Try {                            returnSystem.getproperty (PropertyName); }                        Catch(Accesscontrolexception ex) {if(logger.isinfoenabled ()) {Logger.info ("Allowed to obtain system property [" + PropertyName + "]:" +ex.getmessage ()); }                            return NULL;            }                    }                };        } Beanfactory.registersingleton (System_properties_bean_name, systemproperties); }        if(!Beanfactory.containsbean (System_environment_bean_name)) {Map<String,String>systemenvironment; Try{systemenvironment=system.getenv (); }            Catch(Accesscontrolexception ex) {systemenvironment=NewReadonlysystemattributesmap () {@Overrideprotectedstring Getsystemattribute (String variableName) {Try {                            returnsystem.getenv (variableName); }                        Catch(Accesscontrolexception ex) {if(logger.isinfoenabled ()) {Logger.info ("Not allowed to obtain system environment variable [" + VariableName + "]:" +ex.getmessage ()); }                            return NULL;            }                    }                };        } Beanfactory.registersingleton (System_environment_bean_name, systemenvironment); }    }

Example: Standardbeanexpressionresolver

Spring3 adds support for expression languages by default, using the form of #{bean.xxx} to invoke related property values.

Spring applicationcontext Container Instantiation of Source notes refresh03

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.