热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

6.2dubbo在spring中自定义xml标签源码解析

在6.1如何在spring中自定义xml标签中我们看到了在spring中自定义xml标签的方式。dubbo也是这样来实现的。一META_INFdubbo.xsd比较长,只列出&am

在6.1 如何在spring中自定义xml标签中我们看到了在spring中自定义xml标签的方式。dubbo也是这样来实现的。

6.2  dubbo在spring中自定义xml标签源码解析

一 META_INF/dubbo.xsd

比较长,只列出元素相关的。

 1 xml version="1.0" encoding="UTF-8" standalOne="no"?>
 2 <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 3             xmlns:beans="http://www.springframework.org/schema/beans"
 4             xmlns:tool="http://www.springframework.org/schema/tool"
 5             xmlns="http://code.alibabatech.com/schema/dubbo"
 6             targetNamespace="http://code.alibabatech.com/schema/dubbo">
 7 
 8     。。。
 9 
10    <xsd:complexType name="applicationType">
11         <xsd:attribute name="id" type="xsd:ID">
12             <xsd:annotation>
13                 <xsd:documentation> The unique identifier for a bean. ]]>xsd:documentation>
14             xsd:annotation>
15         xsd:attribute>
16         <xsd:attribute name="name" type="xsd:string" use="required">
17             <xsd:annotation>
18                 <xsd:documentation> The application name. ]]>xsd:documentation>
19             xsd:annotation>
20         xsd:attribute>
21         <xsd:attribute name="version" type="xsd:string">
22             <xsd:annotation>
23                 <xsd:documentation> The application version. ]]>xsd:documentation>
24             xsd:annotation>
25         xsd:attribute>
26         <xsd:attribute name="owner" type="xsd:string">
27             <xsd:annotation>
28                 <xsd:documentation> The application owner name (email prefix). ]]>xsd:documentation>
29             xsd:annotation>
30         xsd:attribute>
31         <xsd:attribute name="organization" type="xsd:string">
32             <xsd:annotation>
33                 <xsd:documentation> The organization name. ]]>xsd:documentation>
34             xsd:annotation>
35         xsd:attribute>
36         <xsd:attribute name="architecture" type="xsd:string">
37             <xsd:annotation>
38                 <xsd:documentation> The architecture. ]]>xsd:documentation>
39             xsd:annotation>
40         xsd:attribute>
41         <xsd:attribute name="environment" type="xsd:string">
42             <xsd:annotation>
43                 <xsd:documentation> The application environment, eg: dev/test/run ]]>xsd:documentation>
44             xsd:annotation>
45         xsd:attribute>
46         <xsd:attribute name="compiler" type="xsd:string">
47             <xsd:annotation>
48                 <xsd:documentation> The java code compiler. ]]>xsd:documentation>
49             xsd:annotation>
50         xsd:attribute>
51         <xsd:attribute name="logger" type="xsd:string">
52             <xsd:annotation>
53                 <xsd:documentation> The application logger. ]]>xsd:documentation>
54             xsd:annotation>
55         xsd:attribute>
56         <xsd:attribute name="registry" type="xsd:string" use="optional">
57             <xsd:annotation>
58                 <xsd:documentation> The application registry. ]]>xsd:documentation>
59             xsd:annotation>
60         xsd:attribute>
61         <xsd:attribute name="monitor" type="xsd:string" use="optional">
62             <xsd:annotation>
63                 <xsd:documentation> The application monitor. ]]>xsd:documentation>
64             xsd:annotation>
65         xsd:attribute>
66         <xsd:attribute name="default" type="xsd:string" use="optional">
67             <xsd:annotation>
68                 <xsd:documentation> Is default. ]]>xsd:documentation>
69             xsd:annotation>
70         xsd:attribute>
71     xsd:complexType>
72 
73     。。。
74 
75     <xsd:element name="application" type="applicationType">
76         <xsd:annotation>
77             <xsd:documentation> The application config ]]>xsd:documentation>
78         xsd:annotation>
79     xsd:element>
80 
81     。。。
82 
83 xsd:schema>

与上一节完全相似。

 

二 META_INF/spring.schemas

1 http\://code.alibabatech.com/schema/dubbo/dubbo.xsd=META-INF/dubbo.xsd

与上一节完全相似。

 

三 DubboBeanDefinitionParser

代码较长,不再贴出来了,与上一节完全相似。

 

四 DubboNamespaceHandler

 1 package com.alibaba.dubbo.config.spring.schema;
 2 
 3 import com.alibaba.dubbo.common.Version;
 4 import com.alibaba.dubbo.config.ApplicationConfig;
 5 import com.alibaba.dubbo.config.ConsumerConfig;
 6 import com.alibaba.dubbo.config.ModuleConfig;
 7 import com.alibaba.dubbo.config.MonitorConfig;
 8 import com.alibaba.dubbo.config.ProtocolConfig;
 9 import com.alibaba.dubbo.config.ProviderConfig;
10 import com.alibaba.dubbo.config.RegistryConfig;
11 import com.alibaba.dubbo.config.spring.AnnotationBean;
12 import com.alibaba.dubbo.config.spring.ReferenceBean;
13 import com.alibaba.dubbo.config.spring.ServiceBean;
14 
15 import org.springframework.beans.factory.xml.NamespaceHandlerSupport;
16 
17 public class DubboNamespaceHandler extends NamespaceHandlerSupport {
18 
19     static {
20         Version.checkDuplicate(DubboNamespaceHandler.class);
21     }
22 
23     public void init() {
24         registerBeanDefinitionParser("application", new DubboBeanDefinitionParser(ApplicationConfig.class, true));
25         registerBeanDefinitionParser("module", new DubboBeanDefinitionParser(ModuleConfig.class, true));
26         registerBeanDefinitionParser("registry", new DubboBeanDefinitionParser(RegistryConfig.class, true));
27         registerBeanDefinitionParser("monitor", new DubboBeanDefinitionParser(MonitorConfig.class, true));
28         registerBeanDefinitionParser("provider", new DubboBeanDefinitionParser(ProviderConfig.class, true));
29         registerBeanDefinitionParser("consumer", new DubboBeanDefinitionParser(ConsumerConfig.class, true));
30         registerBeanDefinitionParser("protocol", new DubboBeanDefinitionParser(ProtocolConfig.class, true));
31         registerBeanDefinitionParser("service", new DubboBeanDefinitionParser(ServiceBean.class, true));
32         registerBeanDefinitionParser("reference", new DubboBeanDefinitionParser(ReferenceBean.class, false));
33         registerBeanDefinitionParser("annotation", new DubboBeanDefinitionParser(AnnotationBean.class, true));
34     }
35 }

功能与上一节完全相似。这里可以看出,dubbo自定义了10个xml元素(也可以从xsd中看出)。从上边也可以看出,会被解析成ServiceBean,该bean极其重要。

 

五 META_INF/spring.handlers

1 http\://code.alibabatech.com/schema/dubbo=com.alibaba.dubbo.config.spring.schema.DubboNamespaceHandler

与上一节完全相似。


推荐阅读
  • Spring常用注解(绝对经典),全靠这份Java知识点PDF大全
    本文介绍了Spring常用注解和注入bean的注解,包括@Bean、@Autowired、@Inject等,同时提供了一个Java知识点PDF大全的资源链接。其中详细介绍了ColorFactoryBean的使用,以及@Autowired和@Inject的区别和用法。此外,还提到了@Required属性的配置和使用。 ... [详细]
  • Spring源码解密之默认标签的解析方式分析
    本文分析了Spring源码解密中默认标签的解析方式。通过对命名空间的判断,区分默认命名空间和自定义命名空间,并采用不同的解析方式。其中,bean标签的解析最为复杂和重要。 ... [详细]
  • 本文讨论了在Spring 3.1中,数据源未能自动连接到@Configuration类的错误原因,并提供了解决方法。作者发现了错误的原因,并在代码中手动定义了PersistenceAnnotationBeanPostProcessor。作者删除了该定义后,问题得到解决。此外,作者还指出了默认的PersistenceAnnotationBeanPostProcessor的注册方式,并提供了自定义该bean定义的方法。 ... [详细]
  • 本文介绍了Web学习历程记录中关于Tomcat的基本概念和配置。首先解释了Web静态Web资源和动态Web资源的概念,以及C/S架构和B/S架构的区别。然后介绍了常见的Web服务器,包括Weblogic、WebSphere和Tomcat。接着详细讲解了Tomcat的虚拟主机、web应用和虚拟路径映射的概念和配置过程。最后简要介绍了http协议的作用。本文内容详实,适合初学者了解Tomcat的基础知识。 ... [详细]
  • 在重复造轮子的情况下用ProxyServlet反向代理来减少工作量
    像不少公司内部不同团队都会自己研发自己工具产品,当各个产品逐渐成熟,到达了一定的发展瓶颈,同时每个产品都有着自己的入口,用户 ... [详细]
  • web.py开发web 第八章 Formalchemy 服务端验证方法
    本文介绍了在web.py开发中使用Formalchemy进行服务端表单数据验证的方法。以User表单为例,详细说明了对各字段的验证要求,包括必填、长度限制、唯一性等。同时介绍了如何自定义验证方法来实现验证唯一性和两个密码是否相等的功能。该文提供了相关代码示例。 ... [详细]
  • 网络请求模块选择——axios框架的基本使用和封装
    本文介绍了选择网络请求模块axios的原因,以及axios框架的基本使用和封装方法。包括发送并发请求的演示,全局配置的设置,创建axios实例的方法,拦截器的使用,以及如何封装和请求响应劫持等内容。 ... [详细]
  • 使用nodejs爬取b站番剧数据,计算最佳追番推荐
    本文介绍了如何使用nodejs爬取b站番剧数据,并通过计算得出最佳追番推荐。通过调用相关接口获取番剧数据和评分数据,以及使用相应的算法进行计算。该方法可以帮助用户找到适合自己的番剧进行观看。 ... [详细]
  • Spring特性实现接口多类的动态调用详解
    本文详细介绍了如何使用Spring特性实现接口多类的动态调用。通过对Spring IoC容器的基础类BeanFactory和ApplicationContext的介绍,以及getBeansOfType方法的应用,解决了在实际工作中遇到的接口及多个实现类的问题。同时,文章还提到了SPI使用的不便之处,并介绍了借助ApplicationContext实现需求的方法。阅读本文,你将了解到Spring特性的实现原理和实际应用方式。 ... [详细]
  • flowable工作流 流程变量_信也科技工作流平台的技术实践
    1背景随着公司业务发展及内部业务流程诉求的增长,目前信息化系统不能够很好满足期望,主要体现如下:目前OA流程引擎无法满足企业特定业务流程需求,且移动端体 ... [详细]
  • MyBatis多表查询与动态SQL使用
    本文介绍了MyBatis多表查询与动态SQL的使用方法,包括一对一查询和一对多查询。同时还介绍了动态SQL的使用,包括if标签、trim标签、where标签、set标签和foreach标签的用法。文章还提供了相关的配置信息和示例代码。 ... [详细]
  • 本文记录了在vue cli 3.x中移除console的一些采坑经验,通过使用uglifyjs-webpack-plugin插件,在vue.config.js中进行相关配置,包括设置minimizer、UglifyJsPlugin和compress等参数,最终成功移除了console。同时,还包括了一些可能出现的报错情况和解决方法。 ... [详细]
  • iOS超签签名服务器搭建及其优劣势
    本文介绍了搭建iOS超签签名服务器的原因和优势,包括不掉签、用户可以直接安装不需要信任、体验好等。同时也提到了超签的劣势,即一个证书只能安装100个,成本较高。文章还详细介绍了超签的实现原理,包括用户请求服务器安装mobileconfig文件、服务器调用苹果接口添加udid等步骤。最后,还提到了生成mobileconfig文件和导出AppleWorldwideDeveloperRelationsCertificationAuthority证书的方法。 ... [详细]
  • 本文介绍了在Mac上安装Xamarin并使用Windows上的VS开发iOS app的方法,包括所需的安装环境和软件,以及使用Xamarin.iOS进行开发的步骤。通过这种方法,即使没有Mac或者安装苹果系统,程序员们也能轻松开发iOS app。 ... [详细]
  • 本文介绍了一个适用于PHP应用快速接入TRX和TRC20数字资产的开发包,该开发包支持使用自有Tron区块链节点的应用场景,也支持基于Tron官方公共API服务的轻量级部署场景。提供的功能包括生成地址、验证地址、查询余额、交易转账、查询最新区块和查询交易信息等。详细信息可参考tron-php的Github地址:https://github.com/Fenguoz/tron-php。 ... [详细]
author-avatar
非徒雨思_184
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有