代码位置:

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. 【nginx网站性能优化篇(3)】反向代理实现负载均衡

    注意,本篇文章为负载均衡的理论篇,后续找个机会推出实战篇.理论篇主要讲述如何配置负载均衡,配置负载均衡不难.难的是真正的实战,比如如何做到多服务器之间的数据共享(session,file等),多cac ...

  2. JAVA:23种设计模式详解(转)

    设计模式(Design Patterns) ——可复用面向对象软件的基础 设计模式(Design pattern)是一套被反复使用.多数人知晓的.经过分类编目的.代码设计经验的总结.使用设计模式是为了 ...

  3. linux下安装Apache(https) 服务器证书安装配置指南

    一.  安装准备 1.    安装Openssl 要使Apache支持SSL,需要首先安装Openssl支持.推荐下载安装openssl-0.9.8k.tar.gz   下载Openssl:http: ...

  4. java教材

    教材blog    !!http://www.w3cschool.cc/java/java-tutorial.html    ok http://www.douban.com/group/topic/ ...

  5. 特殊的css样式

    在一定范围大小变化的div .div { width:auto; height:auto; min-height:100px; min-width:100px; max-height:200px; m ...

  6. python写的第一个简单小游戏-猜数字

    #Filename:game1.py guess=10 running=True while running: try: answer=int(raw_input('Guess what i thin ...

  7. [Codeforces673B]Problems for Round(思路,规律)

    题目链接:http://codeforces.com/contest/673/problem/B 现在有n个题和m个相似的关系,现在要把他们分到2组去. 要求: 1组的所有题比2组难 每个组都得至少有 ...

  8. [Codeforces137A]Postcards and photos(模拟)

    题目链接:http://codeforces.com/contest/137/problem/A 题意:一个人搬东西,每次只能搬相同的东西,最多只能搬相同的东西不超过5个.问最少搬多少次. 模拟就行了 ...

  9. Android Studio修改包名和applicationId的方法

    背景: 如果新做的项目跟以前做的某一个项目十分相似,那么一个简单的方法就是把原来项目拷贝一份,然后修改代码,但是这样包名还是原来项目的包名,还有如果想在同一台手机上同时安装新做的app和原来的app会 ...

  10. Android自动化测试之Monkeyrunner从零开始(三)

    转自http://www.51testing.com/html/81/22381-854342.html 时光过得太快了,一晃离上一篇monkeyrunner系列的博客已经一年多了.这一年多时间经历了 ...