为了方便查看,大家可以点击浅蓝色的目录进行跳转哦
怕下次找不到了?快快点关注鼓励一下嘛~ (╹▽╹) ~
准备工作
1.切换到zookeeper的bin目录
cd myzookeeper/apache-zookeeper-3.6.3-bin/bin
2.关闭防火墙
systemctl stop firewalld
3.看一下网络通不通
建module
改pom
<?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>cloud2020</artifactId>
<groupId>org.example</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>cloud-provider-payment8004</artifactId>
<dependencies>
<dependency>
<groupId>org.example</groupId>
<artifactId>cloud-api-commons</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
写yml
169.168.133.3是zookeeper的ip
主启动
业务类
controller
@RestController
@Slf4j
public class PaymentController {
@Value("${server.port}")
private String serverPort;
@RequestMapping(value = "/payment/zk")
public String paymentzk(){
return "springcloud with zookeeper:"+serverPort+"\t"+ UUID.randomUUID().toString();
}
}
测试
- 启动centOS7上的zookeeper
- 启动主启动类
发现有jar包冲突的问题
- 再修改pom文件
- 重启主启动类
启动成功!!! - 在centOS7上查看
已经成功注册进来
并且可以看到相关信息
- 在浏览器上测试
所有测试全部通过!!!
如果文章内容对您有帮助的话,欢迎点赞加关注哦!比心