1.构建环境
1.1安装zookeeper,参考链接 https://blog.csdn.net/qq_33316784/article/details/88563482
1.2下载运行 dubbo-admin 下载地址:https://github.com/apache/dubbo/tree/2.5.x
环境配置完成后,启动zookeeper和dubbo-admin服务
2.构建dubbo服务消费者,服务提供者
项目结构
创建一个项目springboot-dubbo ,相关pom.xml 依赖:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>top.xzhand.springboot-dubbo</groupId>
<artifactId>springboot-dubbo</artifactId>
<packaging>pom</packaging>
<version>1.0-SNAPSHOT</version>
<modules>
<module>provider</module>
<module>consumer</module>
<module>provider-sdk</module>
</modules>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/>
</parent>
<properties>
<spring.boot.version>2.1.2.RELEASE</spring.boot.version>
</properties>
<dependencies>
<!--springboot相关jar-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.32</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.6</version>
</dependency>
</dependencies>
</project>
新建prodvider-sdk
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>springboot-dubbo</artifactId>
<groupId>top.xzhand.springboot-dubbo</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>provider-sdk</artifactId>
</project>
新建接口类 UserService
package top.xzhand.service;
import top.xzhand.dto.UserInfoDto;
public interface UserService {
Integer insertSelective(UserInfoDto record);
UserInfoDto selectByPrimaryKey(Long id);
Integer updateByPrimaryKeySelective(UserInfoDto record);
}
package top.xzhand.dto;
import lombok.Data;
import java.io.Serializable;
import java.util.Date;
@Data
public class UserInfoDto implements Serializable {
private Long id;
private String username;
private String password;
private String mobile;
private Date createAt;
private Date updateAt;
private Integer status;
private String photoUrl;
private String nickname;
private String wxId;
}
新建模块provider服务提供者
pom.xml