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