关于Dubbo说明及备注

Dubbo的配置文件:

      创建 Spring 配置文件,配置注解扫描 com.chanshuyi.service.impl 包,并引入 spring-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:context="http://www.springframework.org/schema/context"

       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

 

<!-- *** 注解扫描 ** -->

<context:component-scan base-package="com.chanshuyi.service.impl"/>

<!-- ** 导入其他XML文件 ** -->

<import resource="spring-provider.xml"/>

</beans>

注意!这里不要写成 com.chanshuyi.service.impl.*  否则无法成功扫描!

 

 

创建 spring-provider.xml 文件,它是 dubbo 的主要配置文件。

 

<?xml version="1.0" encoding="UTF-8"?>

<!-- 添加 DUBBO SCHEMA -->

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

       xsi:schemaLocation=

       "http://www.springframework.org/schema/beans

        http://www.springframework.org/schema/beans/spring-beans.xsd          

        http://code.alibabatech.com/schema/dubbo

        http://code.alibabatech.com/schema/dubbo/dubbo.xsd"

        >

 

    <!-- 应用名 -->

    <dubbo:application name="dubbodemo-provider"/>

    <!-- 连接到哪个本地注册中心 -->

<dubbo:registry id="dubbodemo"                

              address="zookeeper://localhost:2181"/>

    <!-- 用dubbo协议在20880端口暴露服务 -->

    <dubbo:protocol name="dubbo" port="28080"/>

    <!-- 声明需要暴露的服务接口 -->

<dubbo:service registry="dubbodemo"

 timeout="3000"   

     interface="com.chanshuyi.service.IUserService"

     ref="userService"/>

</beans>

 

 

这里有几个关键参数:applicationregistryprotocolservice

application  指当前应用名称主要用来给 zookeeper 注册中心计   

                算应用间依赖关系。

registry     用来声明一个注册中心,这里声明了一个id registry   

          的注册中心,地址是本地服务器的 2181 端口(这

          里要与zookeeper 配置文件的 clientPort 属性值一致)。

protocol    指该应用用 dubbo 协议在 28080 端口暴露服务,其他

               应用可以通过这个接口调用服务。

service    用来声明需要暴露的服务接口,这里暴露了IUserService  

            接口,并将接口注册到 id dubbodemo 的注册中       

            心,它引用了 Spring 中名为 userService 的类,超

            时时间为 3 秒。

到这里provider 提供者的配置基本上完成,但我们还需要写一个启动类将 provider 启动起来提供服务。

posted @ 2017-05-26 09:15  夜西门吹雪孤城花满楼  阅读(173)  评论(0编辑  收藏  举报