Dubbo 集成Springboot 实战

今天分享Dubbo 集成Springboot 实战:

1、引入jar包:

 <!-- 整合dubbo -->
      <dependency>
          <groupId>io.dubbo.springboot</groupId>
          <artifactId>spring-boot-starter-dubbo</artifactId>
          <version>1.0.0</version>
          <exclusions>
              <exclusion>
                  <artifactId>slf4j-log4j12</artifactId>
                  <groupId>org.slf4j</groupId>
              </exclusion>
          </exclusions>
      </dependency>
      <!-- zookeeper客户端 -->
      <dependency>
          <groupId>com.101tec</groupId>
          <artifactId>zkclient</artifactId>
          <version>0.7</version>
          <exclusions>
              <exclusion>
                  <artifactId>slf4j-log4j12</artifactId>
                  <groupId>org.slf4j</groupId>
              </exclusion>
          </exclusions>
      </dependency>

      <dependency>
          <groupId>org.apache.zookeeper</groupId>
          <artifactId>zookeeper</artifactId>
          <version>3.4.8</version>
          <type>pom</type>
          <exclusions>
              <exclusion>
                  <artifactId>slf4j-log4j12</artifactId>
                  <groupId>org.slf4j</groupId>
              </exclusion>
          </exclusions>
      </dependency>

2、配置文件处理:

spring:
  dubbo:
    application:
      name: nandao-admin-dubbo #应用名
    registry:
      address: zookeeper://zk1-test.nandao.org:8181;zookeeper://zk2-test.nandao.org:8181; #zookeeper地址
      port: 8181 #提供注册的端口
    protocol:
      name: dubbo
      port: 53888 #dubbo服务暴露的端口
    scan: com.nandao.admin #扫描的包名

3、客户端业务接口配置:


import com.alibaba.dubbo.config.annotation.Reference;
 
@RestController
@RequestMapping("/nandao/user")
@Slf4j
public class TestController {

	@Reference
	IManageService iManageService;

 
	@RequestMapping(path = "/getUserDetail")
    @ResponseBody
	public int test(@RequestParam("userId")long userId)
	{
		log.info("测试成功[{}]",userId);
		TblManage taskManage = iManageService.selectByPrimaryKey(userId);
        return 1;
		 
	}

}

4、作为服务方业务接口配置:

import com.alibaba.dubbo.config.annotation.Service;
 
 */
@Service
public class IManageServiceImpl  implements IManageService {


   //业务代码
}

5、如果分模块配置,注意服务的启动类扫描的路径,保证此服务启动类均能扫描到需要的包:

@EnableMBeanExport(registration = RegistrationPolicy.IGNORE_EXISTING)
@EnableTransactionManagement(proxyTargetClass = true)
@SpringBootApplication(exclude = DruidDataSourceAutoConfigure.class)
 
public class AdminRpcApplication {

	public static void main(String[] args) {
		SpringApplication.run(AdminRpcApplication.class, args);
	}

}

比如:此启动类在此目录下

com.nandao.admin.rpc

 它只能扫描此目录名称下的包,切记!!!

到此,分享完毕实战集成,后期会依次分析源码,敬请期待!!!

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

寅灯

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

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

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

打赏作者

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

抵扣说明:

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

余额充值