前面讲到利用XML配置文件示范Dubbo的使用,比如服务提供者的provider.xml配置文件内容为:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:dubbo="http://dubbo.apache.org/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://dubbo.apache.org/schema/dubbo
http:dubbo.apache.org/schema/dubbo/dubbo.xsd">
<dubbo:application name="test-xml-provider" owner="programmer" organization="dubbox"/>
<dubbo:registry address="zookeeper://10.19.50.225:2181"/>
<dubbo:protocol name="dubbo" port="20890" />
<dubbo:service interface="com.starry.testxmlprovider.service.TestDubbo" ref="dubboService" protocol="dubbo" />
<bean id="dubboService" class="com.starry.testxmlprovider.service.impl.TestDubboImpl"/>
</beans>
可以看到Dubbo自定义标签:dubbo:application,dubbo:registry,dubbo:protocol等等,前面我们已经分析过Dubbo标签的定义,并且说明自定义标签的使用和解析过程;本篇博文将针对dubbo自定义标签的解析作一个深入的剖析。
定义好provider.xml配置文件后,通过ClassPathXmlApplicationContext加载xml配置文件。下面给出调用链:
org.springframework.context.support.ClassPathXmlApplicationContext#ClassPathXmlApplicationContext(java.lang.String)
org.springframework.context.support.ClassPathXmlApplicationContext#ClassPathXmlApplicationContext(java.lang.String[], boolean, org.springframework.context.ApplicationContext)
org.springframework.context.support.AbstractApplicationContext#refresh
org.springframework.context.support.AbstractApplicationContext#obtainFreshBeanFactory
org.springframework.context.support.AbstractRefreshableApplicationContext#refreshBeanFactory
org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.support.DefaultListableBeanFactory)
org.springframework.context.support.AbstractXmlApplicationContext#loadBeanDefinitions(org.springframework.beans.factory.xml.XmlBeanDefinitionReader)
org.springframework.beans.factory.support.AbstractBeanDefinitionReader#loadBeanDefinitions(java.lang.String...)
org.springframework.beans.factory.support.AbstractBeanDefinitionReader#loadBeanDefinitions(java.lang.String)
org.springframework.beans.factory.support.AbstractBeanDefinitionReader#