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);
    }
}
相关推荐
BD_Marathon1 分钟前
设计模式——里氏替换原则
java·设计模式·里氏替换原则
Coder_Boy_3 分钟前
Deeplearning4j+ Spring Boot 电商用户复购预测案例中相关概念
java·人工智能·spring boot·后端·spring
css趣多多6 分钟前
add组件增删改的表单处理
java·服务器·前端
雨中飘荡的记忆7 分钟前
Spring Batch实战
java·spring
Java后端的Ai之路14 分钟前
【Spring全家桶】-一文弄懂Spring Cloud Gateway
java·后端·spring cloud·gateway
devmoon16 分钟前
在 Polkadot Runtime 中添加多个 Pallet 实例实战指南
java·开发语言·数据库·web3·区块链·波卡
野犬寒鸦20 分钟前
从零起步学习并发编程 || 第七章:ThreadLocal深层解析及常见问题解决方案
java·服务器·开发语言·jvm·后端·学习
云姜.23 分钟前
java抽象类和接口
java·开发语言
带刺的坐椅24 分钟前
Claude Code Skills,Google A2A Skills,Solon AI Skills 有什么区别?
java·ai·solon·a2a·claudecode·skills
爱学英语的程序员36 分钟前
面试官:你了解过哪些数据库?
java·数据库·spring boot·sql·mysql·mybatis