使用框架:
jdk 1.8
springboot-2.1.3
dubbo-2.6
spring-data-jpa-2.1.5
一、开发dubbo服务接口:
按照Dubbo官方开发建议,创建一个接口项目,该项目只定义接口和model类;
1、创建springboot工程 spring-boot-demo-dubbo-interface
坐标:
com.example
spring-boot-demo-dubbo-interface
0.0.1-SNAPSHOT
添加spring-data-jpa 依赖:
org.springframework.boot spring-boot-starter-data-jpa2、创建model
package com.example.demo.model;
@Entity
public class User implements Serializable{
private static final long serialVersionUID = 1L;
@Id @GeneratedValue
private long id;
private String userName;
private String password;
private int age;
public long getId() {
return id;
}
//省略set get 方法
3、创建接口:
package com.example.demo.service;
import com.example.demo.model.User;
public interface UserService {
public void save(User user);
public String sayHello(String word);
}
4、使用命令 clean install 打包安装到maven仓库。
阿里巴巴提供的dubbo集成springboot开源项目;
参考文档:
https://github.com/apache/dubbo-spring-boot-project/blob/0.2.x/README_CN.md
本工程采用该项目的jar包进行继承:
com.alibaba.boot dubbo-spring-boot-starter 0.2.0二、开发dubbo服务提供者:
1、创建一个Springboot项目spring-boot-demo-dubbo-provide