The difference between static and dynamic Java proxy What scene use?

    Typically only a static proxy proxy class, a plurality of dynamic proxy class that implements an interface in the proxy

    Static agent in advance to know what the agent is, but dynamic proxies do not know what a proxy, only know at runtime.

    JDK dynamic proxy is achieved inside InvocationHandler invoke method inside the interface, but noted that the agency is the interface, which means you business class must implement the interface, proxied by Proxy in the newProxyInstance.

    There is also a dynamic proxy CGLIB, the agent is the class does not need to inherit the business interface is implemented by a subclass of agent derived. At run time, achieve the purpose of dynamic modification modified bytecode class.

    AOP programming that is dynamic proxy using examples based on dynamic proxies, such as the famous Spring framework, Hibernate framework, etc.

Guess you like

Origin www.cnblogs.com/scar1et/p/11955629.html