dubbo快速开始。

1.maven配置

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dubbo</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>spring</artifactId>
                    <groupId>org.springframework</groupId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Zookeeper 用于分布式服务管理 -->
        <dependency>
            <groupId>org.apache.zookeeper</groupId>
            <artifactId>zookeeper</artifactId>
        </dependency>

        <dependency>
            <groupId>com.github.sgroschupf</groupId>
            <artifactId>zkclient</artifactId>
        </dependency>
        <!-- Zookeeper 用于分布式服务管理 end -->

2.dubbo生产者配置

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.0.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
		http://www.springframework.org/schema/task
   		http://www.springframework.org/schema/task/spring-task-4.0.xsd
		http://code.alibabatech.com/schema/dubbo        
		http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
	
	<!-- dubbo服务提供方 -->
	
	<!-- 配置dubbo服务名:用于monitor监控 -->
	<dubbo:application name="service-product"/>
	
	<!-- 配置dubbo的注册中心 -->
	<!--<dubbo:registry protocol="zookeeper" address="192.168.200.140:2181"/>-->

    <!--dubbo直连-->
	<dubbo:registry address="N/A" />
	
	<!-- 配置dubbo协议 -->
	<dubbo:protocol name="dubbo" port="20880"/>
	
	<!-- 将接口暴露到注册中心  ref引用具体的实现类-->
	<dubbo:service ref="testTbService" interface="com.kenick.sport.service.TestTbService" class="com.kenick.sport.serviceImpl.TestTbServiceImpl"/>
    <dubbo:service ref="brandService" interface="com.kenick.sport.service.BrandService" class="com.kenick.sport.serviceImpl.BrandServiceImpl"/>

</beans>

3.dubbo消费者配置

<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
	xmlns:context="http://www.springframework.org/schema/context"
	xmlns:aop="http://www.springframework.org/schema/aop" 
	xmlns:tx="http://www.springframework.org/schema/tx"
	xmlns:task="http://www.springframework.org/schema/task"
	xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
		http://www.springframework.org/schema/beans/spring-beans-4.0.xsd 
		http://www.springframework.org/schema/mvc 
		http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd 
		http://www.springframework.org/schema/context 
		http://www.springframework.org/schema/context/spring-context-4.0.xsd 
		http://www.springframework.org/schema/aop 
		http://www.springframework.org/schema/aop/spring-aop-4.0.xsd 
		http://www.springframework.org/schema/tx 
		http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
		http://www.springframework.org/schema/task
   		http://www.springframework.org/schema/task/spring-task-4.0.xsd
		http://code.alibabatech.com/schema/dubbo        
		http://code.alibabatech.com/schema/dubbo/dubbo.xsd">
	
	<!-- dubbo服务消费方 -->
	
	<!-- 配置dubbo服务名:用于monitor监控 -->
	<dubbo:application name="console"/>
	
	<!-- 配置dubbo的注册中心 -->
<!--	<dubbo:registry protocol="zookeeper" address="192.168.200.140:2181"/>-->
	
	<!-- 配置引用注册中心的服务-->
	<dubbo:reference id="testTbService" interface="com.kenick.sport.service.TestTbService" url="dubbo://127.0.0.1:20880"/>
	<dubbo:reference id="brandService" interface="com.kenick.sport.service.BrandService" url="dubbo://127.0.0.1:20880"/>

	<dubbo:consumer timeout="600000"/>
		
</beans>

4.spring加载dubbo配置文件

	<!-- 加载dubbo的服务消费方法配置文件 -->
	<import resource="classpath:dubbo-consumer-dev.xml"/>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

kenick

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值