当前位置:
首页 >
Zookeeper 服务注册与发现01——服务提供者
发布时间:2025/4/16
39
豆豆
生活随笔
收集整理的这篇文章主要介绍了
Zookeeper 服务注册与发现01——服务提供者
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
<!-- SpringBoot整合zookeeper客户端 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zookeeper-discovery</artifactId><!--先排除自带的zookeeper3.5.3--><exclusions><exclusion><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId></exclusion></exclusions></dependency><!--添加zookeeper3.5.8版本--><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.5.8</version></dependency>
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>dym_cloud2021</artifactId><groupId>com.atguigu.springcloud</groupId><version>1.0-SNAPSHOT</version></parent><modelVersion>4.0.0</modelVersion><artifactId>cloud-provider-payment8004</artifactId><dependencies><!-- SpringBoot整合Web组件 --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><!-- 引入自己定义的api通用包,可以使用Payment支付Entity --><groupId>com.atguigu.springcloud</groupId><artifactId>cloud-api-commons</artifactId><version>${project.version}</version></dependency><!-- SpringBoot整合zookeeper客户端 --><dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-zookeeper-discovery</artifactId><!--先排除自带的zookeeper3.5.3--><exclusions><exclusion><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId></exclusion></exclusions></dependency><!--添加zookeeper3.4.6版本--><dependency><groupId>org.apache.zookeeper</groupId><artifactId>zookeeper</artifactId><version>3.4.6</version></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>application.yml
#8004表示注册到zookeeper服务器的支付服务提供者端口号 server:port: 8004#服务别名----注册zookeeper到注册中心名称 spring:application:name: cloud-provider-paymentcloud:zookeeper:connect-string: 81.70.58.163:2181PaymentMain8004.java
package com.atguigu.springcloud.controller;import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import java.util.UUID;/*** @auther zzyy* @create 2020-02-19 14:16*/ @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();} }PaymentController.java
package com.dym.springcloud.controller;import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController;import java.util.UUID;@RestController @Slf4jpublic class PaymentController {@Value("${server.port}")private String serverPort;@RequestMapping(value = "/payment/zk")public String paymentzk(){return "springcloud with zookeeper: "+serverPort+"\t"+ UUID.randomUUID().toString();} }总结
以上是生活随笔为你收集整理的Zookeeper 服务注册与发现01——服务提供者的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: eureka的自我保护
- 下一篇: Zookeeper 服务注册与发现02—