<!-- dubbo --> <dependency> <groupId>com.alibaba.boot</groupId> <artifactId>dubbo-spring-boot-starter</artifactId> <version>0.2.0</version> </dependency>
一、配置
*.yml文件配置
服务和消费一样,修改name和dubbo的端口不一样就行
dubbo:
application:
name: resm
registry:
protocol: zookeeper
address: 10.xx.xx.xx:2181
protocol:
name: dubbo
port: 20881
二、注入
服务提供方,在需要暴露的类上增加@Service(这个包的com.alibaba.dubbo.config.annotation.Service)
消费方在消费的实例上加入@Reference(这个包com.alibaba.dubbo.config.annotation.Reference)
如:服务方暴露的是
@Service(timeout = 5000)
public class SysmServiceImpl implements ISysmService {
public User getCurrent(String key) {
return new User();
}
}
消费方则
@Component
public class UserDubboServiceImpl implements IUserDubboService {
@Reference
private ISysmService userService;
@Override
public User getUser(String key){
return userService.getCurrent(key);
}
}
三、在启动类上添加@EnableDubbo注解