spring maven 搭建dubbo框架 消费端

本文详细介绍如何搭建基于Dubbo的消费端项目,包括引入必要的依赖、配置注册中心及服务引用等步骤,并通过一个简单的例子验证配置的有效性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1 创建消费端项目 consumer 

2 在pom.xml中引入相关jar包和接口

  	<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-context</artifactId>
	    <version>4.1.6.RELEASE</version>
	</dependency>
 	<dependency>
	    <groupId>org.springframework</groupId>
	    <artifactId>spring-test</artifactId>
	    <version>4.1.6.RELEASE</version>
	</dependency>
	<dependency>
	    <groupId>com.alibaba</groupId>
	    <artifactId>dubbo</artifactId>
	    <version>2.5.3</version>
	    <exclusions>
	    	<exclusion>
	    		<groupId>org.springframework</groupId>
	    		<artifactId>spring</artifactId>
	    	</exclusion>
	    </exclusions>
	</dependency>
	<dependency>
	    <groupId>com.github.sgroschupf</groupId>
	    <artifactId>zkclient</artifactId>
	    <version>0.1</version>
</dependency>
3 将junit 版本改成4.11

4 创建一个源文件夹  src/main/resource

5 在里面创建 applicationContext.xml和applicationContext-dubbo.xml 两个配置文件

6 在applicationContext-dubbo.xml中配置 

    <!-- 消费方应用名,用于计算依赖关系,不是匹配条件,不要与提供方一样 -->  
    <dubbo:application name="wy_consumer" />  
  
    <!-- 使用zookeeper注册中心暴露服务地址 -->  
   
     <dubbo:registry address="zookeeper://192.168.80.141:2181" /> 
    
    <!-- 生成远程服务代理,可以像使用本地bean一样使用userService -->  
    <dubbo:reference id="testService"    interface="com.dubbo.service.Itest" />
7 在applicationContext.xml中 扫描实现类所在的包  引入 dubbo.xml

	<context:component-scan base-package="com.dubbo.provider.TestImpl"></context:component-scan>
	<import resource="classpath:applicationContext-dubbo.xml "/>

8 写个测试类 


测试成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值