Spring boot 集成 dubbo (仅限接口调用方)
1、引入dubbo的JAR
<dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>0.10</version> </dependency>
2、连接到dubbo注册中心:
dubbo:
application: #应用配置,用于配置当前应用信息,不管该应用是提供者还是消费者。
name: ucia-demo-restapi
protocol:
prot: 20880
name: dubbo
registry: #注册中心配置,用于配置连接注册中心相关信息。
address: 10.18.3.67:2181
protocol: zookeeper
3、调用样例:
package com.ulic.ucia.demo.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import com.alibaba.dubbo.config.annotation.Reference; import com.ulic.im.client.util.UlimClientUtil; import com.ulic.ucia.framework.log.Log; import com.ulic.ucia.framework.log.LogFactory; import com.ulic.um.service.AppRoleService; @RestController @RequestMapping("/dubbo") public class DubboController { private final Log log = LogFactory.getLog(DubboController.class); @Reference AppRoleService appRoleService; @RequestMapping("/getTicket") public String test() throws Exception { String[] tmp = appRoleService.getAppRoles(UlimClientUtil.getAppInfo(), "UM"); log.debug(tmp.toString()); return tmp.toString(); } } 注意: a.@Reference 用阿里提供的注解。 b.AppRoleService 为接口提供方的接口类 c.UlimClientUtil.getAppInfo() 用微服务仓库中2.0.7以上的版本。
if you want to go fast,go alone,if you want to go far,go together