栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

Dubbo 集成Springboot 实战

Dubbo 集成Springboot 实战

今天分享Dubbo 集成Springboot 实战:

1、引入jar包:

 
      
          io.dubbo.springboot
          spring-boot-starter-dubbo
          1.0.0
          
              
                  slf4j-log4j12
                  org.slf4j
              
          
      
      
      
          com.101tec
          zkclient
          0.7
          
              
                  slf4j-log4j12
                  org.slf4j
              
          
      

      
          org.apache.zookeeper
          zookeeper
          3.4.8
          pom
          
              
                  slf4j-log4j12
                  org.slf4j
              
          
      

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

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

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/688570.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号