代码位置:

motan-core的目录下

     


motan中使用spring管理配置对象。motan利用Spring的spi机制创建了自定义标签和相应的标签处理代码。具体使用方法见这篇。本文以motan为例,探讨如何扩展spring的schema.

1.首先,如果要自定义标签,不得不加上响应的xsd文件,这个文件可以对xml的格式进行约束。可以看到以下的自定义标签应该遵循的格式。对于新增的xsd文件,还要建立一个spring.schemas文件,加上这个xsd文件。

 <?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright 2009-2016 Weibo, Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
--> <xsd:schema xmlns="http://api.weibo.com/schema/motan"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:tool="http://www.springframework.org/schema/tool"
xmlns:beans="http://www.springframework.org/schema/beans"
targetNamespace="http://api.weibo.com/schema/motan"> <xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:import namespace="http://www.springframework.org/schema/tool"/>
<xsd:import namespace="http://www.springframework.org/schema/beans"/> <xsd:complexType name="abstractConfig">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="beans:property" minOccurs="0" maxOccurs="unbounded" />
</xsd:choice>
<xsd:anyAttribute namespace="##other" processContents="lax" />
</xsd:complexType>
<xsd:complexType name="abstractRegistryConfig" >
<xsd:complexContent>
<xsd:extension base="abstractConfig">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="name" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册名称. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="regProtocol" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册协议. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="address" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心地址. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="username" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心登录用户名. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="password" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心登录密码. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="port" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心缺省端口. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="connectTimeout" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心连接超时时间(毫秒). ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="requestTimeout" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心请求超时时间(毫秒). ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="registrySessionTimeout" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心会话超时时间(毫秒). ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="registryRetryPeriod" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ registryRetryPeriod. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="check" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 启动时检查注册中心是否存在. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="dynamic" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 在该注册中心是否自动注册. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="register" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 在该注册中心上服务是否暴露. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="subscribe" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 在该注册中心上服务是否引用. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="excise" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心移除策略,仅对vitage生效. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="default" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ is default protocol ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute> </xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:complexType name="abstractInterfaceConfig" >
<xsd:complexContent>
<xsd:extension base="abstractConfig">
<xsd:attribute name="proxy" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 代理类型. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute> <xsd:attribute name="group" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 服务分组. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute> <xsd:attribute name="version" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ version. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="throwException" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ throwException. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="requestTimeout" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ requestTimeout. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="connectTimeout" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 连接请求超时时间(毫秒). ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="retries" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ retries ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="filter" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 过滤器配置. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="listener" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 监听器配置. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="connections" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 连接数限制,0表示共享连接,否则为该服务独享连接数;默认共享. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="application" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 应用信息. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="module" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 模块信息. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="shareChannel" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 是否共享channel. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="timeout" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The method invoke timeout. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="actives" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The max active requests. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="async" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The method does async. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="mock" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ Use service mock implemention. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="check" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 检查服务提供者是否存在 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="registry" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 注册中心的id列表,多个用“,”分隔,如果为空,则使用所有的配置中心. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="register" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 在该注册中心上服务是否暴露. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="subscribe" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 在该注册中心上服务是否引用. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="accessLog" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ accessLog ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="localServiceAddress" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 当使用VintageRetryLookupRegistry时,从config server同步三次失败并且feature.motanmcq.loadaddressfromfs开关打开时,把这个配置指定的地址作为服务地址,以逗号分割 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="usegz" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 是否开启gzip压缩.只有compressMotan的codec才能支持 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="mingzSize" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 开启gzip压缩的阈值.usegz开关开启,且传输数据大于此阈值时,才会进行gzip压缩。只有compressMotan的codec才能支持 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="codec" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 协议编码. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType> <xsd:complexType name="abstractProtocolConfig">
<xsd:complexContent>
<xsd:extension base="abstractConfig">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="name" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[ 服务协议 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="serialization" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 序列化方式 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="payload" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 最大请求数据长度 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="buffer" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 缓存区大小 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="heartbeat" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 心跳间隔 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="transporter" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 网络传输方式 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="threads" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 线程池大小 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="iothreads" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ IO线程池大小 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="requestTimeout" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 请求超时 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="minClientConnection" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ minClientConnection ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="maxClientConnection" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ maxClientConnection ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute> <xsd:attribute name="minWorkerThread" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ minWorkerThread ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="maxWorkerThread" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ maxWorkerThread ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="maxContentLength" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ maxContentLength ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="maxServerConnection" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ maxContentLength ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="poolLifo" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ is poolLifo ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="lazyInit" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ is lazyInit ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="endpointFactory" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ endpointFactory ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="cluster" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ cluster ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="loadbalance" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ loadbalance ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="haStrategy" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ haStrategy ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="workerQueueSize" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ workerQueueSize ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="acceptConnections" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ acceptConnections ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute> <xsd:attribute name="proxy" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ proxy ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute> <xsd:attribute name="filter" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ filter ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="retries" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ retries ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="async" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ is async ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="queueSize" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 线程池队列大小 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="accepts" type="xsd:integer" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 最大接收连接数 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="dispatcher" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 信息线程模型派发方式 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="server" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 服务器端实现 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="client" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 客户端端实现 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute> <xsd:attribute name="codec" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ codec ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="default" type="xsd:boolean" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ is default protocol ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="switcherService" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ switcherService ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="heartbeatFactory" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ heartbeatFactory ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType> <xsd:element name="protocol" type="abstractProtocolConfig">
<xsd:annotation>
<xsd:documentation><![CDATA[ Service provider config ]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="registry" type="abstractRegistryConfig">
<xsd:annotation>
<xsd:documentation><![CDATA[ Registry config ]]></xsd:documentation>
</xsd:annotation>
</xsd:element>
<xsd:element name="method">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[ The method name (method.toString()). ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="argumentTypes" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 参数类型(逗号分隔), 无参数用void. 如果方法无重载,则可不写 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="requestTimeout" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The method invoke timeout. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="retries" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The method retry times. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
</xsd:element>
<xsd:element name="service">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="abstractInterfaceConfig">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="method" minOccurs="0" maxOccurs="unbounded" />
<xsd:element ref="beans:property" minOccurs="0" maxOccurs="unbounded" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="export" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 服务暴露的方式,包含协议及端口号,多个协议端口用"," 分隔. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="basicService" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 基本service配置 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="host" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 如果有多个ip,但只想暴露指定的某个ip,设置该参数 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="interface" type="xsd:token">
<xsd:annotation>
<xsd:documentation><![CDATA[ Defines the interface to advertise for this service in the service registry. ]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:expected-type type="java.lang.Class"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute> <xsd:attribute name="ref" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The service implementation instance bean id. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="class" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The service implementation class name. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute> <xsd:attribute name="path" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ The service path. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="serialization" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 序列化方式. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="extConfig" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 扩展配置. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element>
<xsd:element name="referer">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="abstractInterfaceConfig">
<xsd:choice minOccurs="0" maxOccurs="unbounded">
<xsd:element ref="method" minOccurs="0" maxOccurs="unbounded" />
<xsd:element ref="beans:property" minOccurs="0" maxOccurs="unbounded" />
</xsd:choice>
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="protocol" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 使用的协议 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="interface" type="xsd:token" use="required">
<xsd:annotation>
<xsd:documentation><![CDATA[ The service interface class name. ]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:expected-type type="java.lang.Class"/>
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="client" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 客户端类型 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="directUrl" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[点对点直连服务提供地址 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="basicReferer" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 基本referer配置 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="extConfig" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 扩展配置. ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element> <xsd:element name="basicService">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="abstractInterfaceConfig">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="export" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 暴露的协议及端口,多个协议端口之间用","分隔 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="host" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 如果有多个ip,但只想暴露指定的某个ip,设置该参数 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element> <xsd:element name="basicReferer">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="abstractInterfaceConfig">
<xsd:attribute name="id" type="xsd:ID" />
<xsd:attribute name="protocol" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ 使用的协议 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="mean" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ SLA平均响应时间 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="p90" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ SLA90%的响应时间 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="p99" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ SLA99%的响应时间 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="p999" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ SLA999%的响应时间 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="errorRate" type="xsd:string" use="optional">
<xsd:annotation>
<xsd:documentation><![CDATA[ SLA错误率 ]]></xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element> <xsd:element name="spi">
<xsd:complexType>
<xsd:complexContent>
<xsd:extension base="abstractConfig">
<xsd:attribute name="interfaceClass" type="xsd:token">
<xsd:annotation>
<xsd:documentation><![CDATA[ spi interface ]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:expected-type type="java.lang.Class" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
<xsd:attribute name="spiClass" type="xsd:token">
<xsd:annotation>
<xsd:documentation><![CDATA[ spi impl ]]></xsd:documentation>
<xsd:appinfo>
<tool:annotation>
<tool:expected-type type="java.lang.Class" />
</tool:annotation>
</xsd:appinfo>
</xsd:annotation>
</xsd:attribute>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:element> </xsd:schema>

2.有个标签的格式,还需要标签的处理器,标签的处理器只要简单的继承NamespaceHandlerSupport这个类,具体的类如下,其中在init方法中,定义了标签和对应的解析器。motan中的对XML的解析起都是MotanBeanDefinitionParser,最终一对标签,最终转化为相应的BeanDefination.并放在一个并发的hashMap中,key为id,value是相应的beanDefination.

public class MotanNamespaceHandler extends NamespaceHandlerSupport {
public final static Set<String> protocolDefineNames = new ConcurrentHashSet<String>();
public final static Set<String> registryDefineNames = new ConcurrentHashSet<String>();
public final static Set<String> basicServiceConfigDefineNames = new ConcurrentHashSet<String>();
public final static Set<String> basicRefererConfigDefineNames = new ConcurrentHashSet<String>(); @Override
public void init() {
registerBeanDefinitionParser("referer", new MotanBeanDefinitionParser(RefererConfigBean.class, false));
registerBeanDefinitionParser("service", new MotanBeanDefinitionParser(ServiceConfigBean.class, true));
registerBeanDefinitionParser("protocol", new MotanBeanDefinitionParser(ProtocolConfig.class, true));
registerBeanDefinitionParser("registry", new MotanBeanDefinitionParser(RegistryConfig.class, true));
registerBeanDefinitionParser("basicService", new MotanBeanDefinitionParser(BasicServiceInterfaceConfig.class, true));
registerBeanDefinitionParser("basicReferer", new MotanBeanDefinitionParser(BasicRefererInterfaceConfig.class, true));
registerBeanDefinitionParser("spi", new MotanBeanDefinitionParser(SpiConfigBean.class, true));
} }

motan解读:添加spring 支持的更多相关文章

  1. myeclipse重新添加spring支持

    需求:添加一次可能失败,需要再添加,但是一般点击右键add spring capabilities 不存在了 解决办法: 打开工程找到.project 注释掉spring支持 重新项目右键加入支持即可 ...

  2. 【liferay】3、liferay 添加spring支持

    1.添加对应的spring的jar 地址:https://spring.io/projects 选中springframework 进入git源码的地方,看简介 我们需要编译好的jar 当然也可以自己 ...

  3. 手动添加SSH支持、使用c3p0

    之前做的笔记,现在整理一下:大家有耐心的跟着做就能成功: SSH(struts2.spring.hibernate) *  struts2      *  充当mvc的角色 *  hibernate ...

  4. Spring Boot 添加Shiro支持

    前言: Shiro是一个权限.会话管理的开源Java安全框架:Spring Boot集成Shiro后可以方便的使用Session: 工程概述: (工程结构图) 一.建立Spring Boot工程 参照 ...

  5. 使用Spring Boot开发Web项目(二)之添加HTTPS支持

    上篇博客使用Spring Boot开发Web项目我们简单介绍了使用如何使用Spring Boot创建一个使用了Thymeleaf模板引擎的Web项目,当然这还远远不够.今天我们再来看看如何给我们的We ...

  6. Spring Boot 添加JSP支持【转】

    Spring Boot 添加JSP支持 大体步骤: (1)            创建Maven web project: (2)            在pom.xml文件添加依赖: (3)     ...

  7. IDEA02 利用Maven创建Web项目、为Web应用添加Spring框架支持、bean的创建于获取、利用注解配置Bean、自动装配Bean、MVC配置

    1 环境版本说明 Jdk : 1.8 Maven : 3.5 IDEA : 专业版 2017.2 2 环境准备 2.1 Maven安装及其配置 2.2 Tomcat安装及其配置 3 详细步骤 3.1 ...

  8. step6----->往工程中添加spring boot项目------->修改pom.xml使得我的project是基于spring boot的,而非直接基于spring framework

    文章内容概述: spring项目组其实有多个projects,如spring IO platform用于管理external dependencies的版本,通过定义BOM(bill of mater ...

  9. eclipse 新建 maven 项目 添加 spring hibernate 的配置文件 详情

    主要配置文件 pom.xml 项目的maven 配置文件 管理项目所需 jar 依赖支持 web.xml 项目的总 配置文件  :添加 spring和hibernate 支持 applicationC ...

随机推荐

  1. Makefile笔记

    一个简单的Makefile描述规则组成: TARGET...:PREREQUISITES... COMMANDS... ... target:规则的目标.通常是程序中间或者最后要生成的文件名,也可以是 ...

  2. MIT算法导论——第一讲.Analysis of algorithm

    本栏目(Algorithms)下MIT算法导论专题是个人对网易公开课MIT算法导论的学习心得与笔记.所有内容均来自MIT公开课Introduction to Algorithms中Charles E. ...

  3. Visual StudioTools for Unity 使用技巧2

    在之前的博客介绍了 Visual Studio Tools for Unity的安装和使用. http://www.cnblogs.com/petto/p/3886811.html 其实这个工具还提供 ...

  4. Python基本程序结构

    条件判断: 计算机之所以能做很多自动化的任务,因为它可以自己做条件判断.比如,输入用户年龄,根据年龄打印不同的内容,在Python程序中,用if语句实现:

  5. 【Linux常用工具】03. Linux性能测试工具ab

    在Apache服务器的套件中,有一个叫做 ab (ApacheBench) 的工具. ApacheBench 主要是用来测试Apache服务器执行效率用的 ApacheBench 可以针对某个特定的 ...

  6. vs2012 arcgis engine 10 丢失arcgis模板

    1.Visual Studio 2012环境下安装ArcGIS Engine 10 Visual Studio 2012环境下安装ArcObject SDK for the Microsoft .Ne ...

  7. Apple开发者账号申请学习方式

    http://jingyan.baidu.com/article/414eccf610e7c76b431f0a94.html https://developer.apple.com/wwdc/sche ...

  8. 用paint 计算字符串的像素宽度

    方法1: //直接返回参数字符串所占用的像素宽度 Paint paint = new Paint(); width = paint.measureText(str); 有一些view可以直接得到pai ...

  9. eclipse导入javax.servlet.*的方法

    1.下载web应用服务器tomact,网址http://tomcat.apache.org/download-80.cgi 这个根据自己系统进行选择. 2.将其加压到电脑中 3.在eclipse中添加 ...

  10. UVa 10253 (组合数 递推) Series-Parallel Networks

    <训练之南>上的例题难度真心不小,勉强能看懂解析,其思路实在是意想不到. 题目虽然说得千奇百怪,但最终还是要转化成我们熟悉的东西. 经过书上的神分析,最终将所求变为: 共n个叶子,每个非叶 ...