您好,欢迎来到客趣旅游网。
搜索
您的当前位置:首页【dubbo源码解读系列】之二 dubbo代码启动入口解析(自定义main方法)

【dubbo源码解读系列】之二 dubbo代码启动入口解析(自定义main方法)

来源:客趣旅游网

dubbo的启动方式

dubbo启动Demo代码

dubbo源码的工程中有一个例子工程
在工程下有一个服务端工程,该工程的启动代码见Provider类

public class Provider {

    public static void main(String[] args) throws Exception {
        //Prevent to get IPV6 address,this way only work in debug mode
        //But you can pass use -Djava.net.preferIPv4Stack=true,then it work well whether in debug mode or not
        System.setProperty("java.net.preferIPv4Stack", "true");
        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[]{"META-INF/spring/dubbo-demo-provider.xml"});
        context.start();

        System.in.read(); // press any key to exit
    }

}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
       xmlns="http://www.springframework.org/schema/beans"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd">

    <!-- provider's application name, used for tracing dependency relationship -->
    <dubbo:application name="demo-provider"/>

    <!-- 我自己在本地搞了一个zookeeper -->
    <dubbo:registry address="zookeeper://127.0.0.1:2181"/>

    <!-- use dubbo protocol to export service on port 20880 -->
    <dubbo:protocol name="dubbo" port="20880"/>

    <!-- service implementation, as same as regular local bean -->
    <bean id="demoService" class="com.alibaba.dubbo.demo.provider.DemoServiceImpl"/>

    <!-- declare the service interface to be exported -->
    <dubbo:service interface="com.alibaba.dubbo.demo.DemoService" ref="demoService"/>

    <dubbo:annotation package="com.alibaba.dubbo.demo.provider" />

</beans>

一脸茫然的有没有,完全看不到dubbo框架代码的踪影呀!

dubbo代码切入

Spring会默认加载spring.handlers和spring.schemas,从而感知schema描述文档,从中我们可以看到schema的处理器。
dubbo的spring.handlers内容与位置如下:

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

从配置可以看出spring通过DubboNamespaceHandler来加载dubbo的配置,好啦dubbo的入口已经找到了。
更精彩内容庆关注后续博文…

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- kqyc.cn 版权所有 赣ICP备2024042808号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务