您的位置:首页 > 编程语言 > Java开发

JDK Dynamic Proxy and cglib

2012-09-11 10:12 316 查看
PART 1 Understand How To Use JDK Dynamic Proxy

If you know it, you have to admit that the JDK Dynamic Proxy is designed elegantly. We can encapsulate the interceptor logic in a class which implements the InvocationHandler interface, after that we are able to dynamically create a proxy instance by calling
Proxy.newProxyInstance(classloader, class, invocationhandler). Simple enough, Hum?

PART 2 The Limitations Of JDK Dynamic Proxy

The proxy is interface oriented. Intrusive. Sometimes we need to create a proxy for a class indeed, rather than an interface. So cglib comes into play.

PART 3 How To Use cglib

cglib shares similar usage with JDK Proxy Dynamic. First, we encapsulate the interceptor logic in a class which implements the MethodInterceptor interface, then we call Enhancer's create() to instantiate a proxy dynamically.

Another noteworthy part is cglib's CallbackFilter. What's the counterpart of JDK Dynamic Proxy?

PART 4 Spring

Spring employs JDK Dynamic Proxy for interface proxy, and cglib for class proxy.

PART 5 Hibernate
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: