"Spring Source Learning" Beanpostprocessor Interface Learning

Source: Internet
Author: User

One: Meaning function

The ==>beanpostprocessor interface is one of many spring-to-developer custom logic expansion interfaces that are provided to developers in the bean lifecycle.

Two: interface definition

Package Org.springframework.beans.factory.config;import org.springframework.beans.BeansException;  Public Interface beanpostprocessor {    /* *     *IOC The Bean in the container is instantiated     before executing the */    Object Postprocessbeforeinitialization (Object Bean, String beanname) throws beansexception;     /* *     Execute     after the bean in the *IOC container is instantiated *     /Object Postprocessafterinitialization (object Bean, String beanname) throws beansexception;}
View Code

Three: custom instance (executes when the IOC is instantiated and prints the content. XML configuration beans, or annotated annotations to take effect)

Package Com.mobile.thinks.manages.study;import Org.springframework.beans.beansexception;import Org.springframework.beans.factory.config.beanpostprocessor;import org.springframework.stereotype.component;@ Component Public classMybeanpostprocessor implements beanpostprocessor{/** * The Bean in the IOC container executes the method before it is instantiated*/@Override PublicObject Postprocessbeforeinitialization (Object bean, String beanname) throws Beansexception {Cl the<?> cls=Bean.getclass (); System. out. println ("sxf "Custom instantiation before" Postprocessbeforeinitialization classpath ==>"+CLS); System. out. println ("SXF "Before custom instantiation" Postprocessbeforeinitialization initializes the name of the object ==>"+beanname); returnBean; }        /** * The Bean in the IOC container executes the method after it is instantiated*/@Override PublicObject Postprocessafterinitialization (Object bean, String beanname) throws Beansexception {class
    <?> cls=Bean.getclass (); System. out. println ("sxf "After custom instantiation" Postprocessbeforeinitialization classpath ==>"+CLS); System. out. println ("sxf "After custom instantiation" Postprocessbeforeinitialization initializes the name of the object ==>"+beanname); returnBean; }        }
View Code

Four: Spring Internal example

"Spring Source Learning" Beanpostprocessor Interface Learning

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.