Dynamic proxy, spring two core knowledge beanfactory, AOP framework!

Source: Internet
Author: User

Feature encapsulation and Configuration:

Beanfactory of the factory class is responsible for creating instance objects of the target class or proxy class, and implementing switching through the configuration file. The getbean method returns a corresponding instance object based on the parameter string, if the class name corresponding to the parameter string in the configuration file is not proxyfactorybean, the instance object of this class is directly returned, and the object returned by the getproxy method of this object is returned.

Beanfactory constructor accepts the input stream object representing the configuration file. The configuration file format is as follows:

Export xxx=java.util.araylist;xxx=cn.itcast.proxyfactorybean;xxx.tar get = java. util. arraylist; XXX. d

Evice = cn. itcast. mydvice;

 

The proxybean acts as a dynamic proxy for encapsulation and survival. The configuration information required for the factory class is: Target and notification.

Object OBJ = beanfactory. getbean ("XXX"); it means that there is a factory beanfactory that generates the factory of JavaBean, and there is a getbean (string name) method, create a JavaBean object based on the name, which is configured in the configuration file.# Xxx = Java. util. araylist; input # XXX tells spring to create a Java for me. util. arraylist instance object. If getbean finds that it is not a special class such as proxyfactorybean, it creates such an instance object, Else. Instead of returning its instance object, it calls the method in the proxyfactorybean class, create a proxy.

Dynamically generate internal classCodeAnalysis:

The dynamically generated class implements the collection interface (multiple interfaces can be implemented). The generated class includes all the methods in the collection interface and a constructor that accepts the invocationhandler parameter, the constructor receives an invocationhandler object. Why do I need to define an interface and reference it in one place? I need to use the interface when I don't know the name!

 

 

The principle knowledge of Spring framework is the proxy. The core code is implemented as follows:

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.