今天分享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
它只能扫描此目录名称下的包,切记!!!
到此,分享完毕实战集成,后期会依次分析源码,敬请期待!!!



