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