手写RPC框架之集成spring(基于xml配置文件方式)

Dubbo 采用全 Spring 配置方式,透明化接入应用,对应用没有任何 API 侵入,只需用 Spring 加载 Dubbo 的配置即可,Dubbo 基于 Spring 的 Schema 扩展 进行加载。

同样,我们的RPC框架也集成Spring帮助我们更好地实现基于配置的可定制化的加载。

自定义标签及解析

标签 用途
<rpc:service/> 用于服务提供方配置需要注册的服务
<rpc:reference/> 用于服务消费方配置引用的服务
<rpc:registry/> 用于配置可选的服务注册中心,如Zookeeper和Nacos
<rpc:serialize/> 用于配置可选的序列化方式,如kryo和protostuff

如何使用自定义标签呢?需要的文件(按照spring加载、解析的顺序)有以下五个基本文件:

  • ①spring.schemas
  • ②XSD文件
  • ③spring.handlers
  • ④NamespaceHandler
  • ⑤BeanDefinitionParser

首先是META-INF 需要定义的三个文件:
在这里插入图片描述
spring.schemas : spring.schemas是告诉spring容器我们的自定义的xsd文件在哪里;左半边的网址是自己定义的,不是真实存在的。

http\://www.mya.com/schema/rpc.xsd=/META-INF/rpc.xsd

spring.handlers : hanlers文件指向的NamespaceHandlers类,目的是为了注册我们对应标签的解析类。

http\://www.mya.com/schema/rpc=org.whu.mya.spring.schema.RpcSpaceHandler

rpc.xsd : XSD文件是对于我们定义bean对象时可以使用的属性限制或者说支持的那些属性的配置。

<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns="http://www.mya.com/schema/rpc"
            xmlns:xsd="http://www.w3.org/2001/XMLSchema"
            targetNamespace="http://www.mya.com/schema/rpc"
            elementFormDefault="qualified">

    <xsd:complexType name="service-type">
        <xsd:attribute name="id" type="xsd:string">
        </xsd:attribute>
        <xsd:attribute name="interface" type="xsd:string">
        </xsd:attribute>
        <xsd:attribute name="ref" type="xsd:string">
        </xsd:attribute>
        <xsd:attribute name="group" type="xsd:string">
        </xsd:attribute>
    </xsd:complexType>

    <xsd:complexType name="reference-type">
        <xsd:attribute name="id" type="xsd:string">
        </xsd:attribute>
        <xsd:attribute name="interface" type="xsd:string">
        </xsd:attribute>
        <xsd:attribute name
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值