动态代理扩展

扩展说明

Invoker 接口转换成业务接口。

扩展接口

com.alibaba.dubbo.rpc.ProxyFactory

扩展配置

  1. <dubbo:protocol proxy="xxx" />
  2. <!-- 缺省值配置,当<dubbo:protocol>没有配置proxy属性时,使用此配置 -->
  3. <dubbo:provider proxy="xxx" />

已知扩展

  • com.alibaba.dubbo.rpc.proxy.JdkProxyFactory
  • com.alibaba.dubbo.rpc.proxy.JavassistProxyFactory

    扩展示例

Maven 项目结构:

  1. src
  2. |-main
  3. |-java
  4. |-com
  5. |-xxx
  6. |-XxxProxyFactory.java (实现ProxyFactory接口)
  7. |-resources
  8. |-META-INF
  9. |-dubbo
  10. |-com.alibaba.dubbo.rpc.ProxyFactory (纯文本文件,内容为:xxx=com.xxx.XxxProxyFactory)

XxxProxyFactory.java:

  1. package com.xxx;
  2. import com.alibaba.dubbo.rpc.ProxyFactory;
  3. import com.alibaba.dubbo.rpc.Invoker;
  4. import com.alibaba.dubbo.rpc.RpcException;
  5. public class XxxProxyFactory implements ProxyFactory {
  6. public <T> T getProxy(Invoker<T> invoker) throws RpcException {
  7. // ...
  8. }
  9. public <T> Invoker<T> getInvoker(T proxy, Class<T> type, URL url) throws RpcException {
  10. // ...
  11. }
  12. }

META-INF/dubbo/com.alibaba.dubbo.rpc.ProxyFactory:

  1. xxx=com.xxx.XxxProxyFactory

原文: http://dubbo.apache.org/#!/docs/dev/impls/proxy-factory.md?lang=zh-cn