动态代理扩展

扩展说明

Invoker 接口转换成业务接口。

扩展接口

org.apache.dubbo.rpc.ProxyFactory

扩展配置

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

已知扩展

  • org.apache.dubbo.rpc.proxy.JdkProxyFactory
  • org.apache.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. |-org.apache.dubbo.rpc.ProxyFactory (纯文本文件,内容为:xxx=com.xxx.XxxProxyFactory)

XxxProxyFactory.java:

  1. package com.xxx;
  2. import org.apache.dubbo.rpc.ProxyFactory;
  3. import org.apache.dubbo.rpc.Invoker;
  4. import org.apache.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/org.apache.dubbo.rpc.ProxyFactory:

  1. xxx=com.xxx.XxxProxyFactory

最后修改 December 16, 2022: Fix check (#1736) (97972c1)