Dubbo之消费端服务RPC调用

在消费端服务是基于接口调用Provider端提供的服务,所以在消费端并没有服务公共接口的实现类。

  1. 使用过程中利用注解@DubboReference将目标接口作为某个类的字段属性,在解析该类时获取全部字段属性并单独关注解析存在注解@DubboReference的字段属性。
  2. 通过步骤1得到服务公共接口类型,在生成RootBeanDefinition时设置其Class属性为**ReferenceBean,**最终将服务公共接口注册至IOC容器中。
  3. 通过JdkDynamicAopProxy对服务公共接口生成代理。

ReferenceAnnotationBeanPostProcessor重置服务目标类在IOC注册表class的属性为ReferenceBean。

java 复制代码
public class ReferenceBean<T> implements FactoryBean<T>{
    @Override
    public T getObject() {
        if (lazyProxy == null) {
            // 对目标类代理处理
            createLazyProxy();
        }
        return (T) lazyProxy;
    }

    private void createLazyProxy() {

        ProxyFactory proxyFactory = new ProxyFactory();
        proxyFactory.setTargetSource(new DubboReferenceLazyInitTargetSource());
        proxyFactory.addInterface(interfaceClass);
        Class<?>[] internalInterfaces = AbstractProxyFactory.getInternalInterfaces();
        for (Class<?> anInterface : internalInterfaces) {
            proxyFactory.addInterface(anInterface);
        }
        if (!StringUtils.isEquals(interfaceClass.getName(), interfaceName)) {
            Class<?> serviceInterface = ClassUtils.forName(interfaceName, beanClassLoader);
            proxyFactory.addInterface(serviceInterface);
        }
        //jdk基于接口代理
        this.lazyProxy = proxyFactory.getProxy(this.beanClassLoader);
    }
}
相关推荐
tb_first21 小时前
LangChain4j简单入门
java·spring boot·langchain4j
独自破碎E21 小时前
【BISHI9】田忌赛马
android·java·开发语言
范纹杉想快点毕业21 小时前
实战级ZYNQ中断状态机FIFO设计
java·开发语言·驱动开发·设计模式·架构·mfc
smileNicky1 天前
布隆过滤器怎么提高误差率
java
それども1 天前
分库分表的事务问题 - 怎么实现事务
java·数据库·mysql
Java面试题总结1 天前
基于 Java 的 PDF 文本水印实现方案(iText7 示例)
java·python·pdf
马猴烧酒.1 天前
【面试八股|Java集合】Java集合常考面试题详解
java·开发语言·python·面试·八股
测试工程师成长之路1 天前
Serenity BDD 框架:Java + Selenium 全面指南(2026 最新)
java·开发语言·selenium
lang201509281 天前
Java JSON绑定API:JSR 367详解
java·java-ee
eWidget1 天前
随机森林原理:集成学习思想 —— Java 实现多棵决策树投票机制
java·数据库·随机森林·集成学习·金仓数据库