Spring Cloud Zookeeper整合

问题描述

我试图编写自己的服务,该服务将使用从zookeeper加载的配置,但是看起来像Spring Boot忽略了具有连接属性的bootstrap.yml。

这是我的bootstrap.yml:

spring:
  application:
    name: foo
  cloud:
    zookeeper:
      connect-string: 192.168.39.227:30239
      config:
        enabled: true
        root: configuration
        defaultContext: apps
        profileSeparator: '::'

我已将spring手册中的所有依赖项添加到build.gradle文件中

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-data-rest'
    implementation 'org.springframework.boot:spring-boot-starter-jersey'
    implementation 'org.springframework.boot:spring-boot-starter-web'
    implementation 'org.springframework.cloud:spring-cloud-starter-zookeeper-config'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'
}

这是我的主要课程代码:

@SpringBootApplication
public class AccessServiceApplication {
    public static void main(String[] args) {
        SpringApplication.run(AccessServiceApplication.class,args);
    }
}

但是当我启动bootRun任务时,我看到不断的错误:

020-09-12 20:09:06.733  INFO 14075 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn          : SASL config status: Will not attempt to authenticate using SASL (unknown error)
2020-09-12 20:09:06.734  WARN 14075 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn          : Session 0x0 for sever localhost/127.0.0.1:2181,Closing socket connection. Attempting reconnect except it is a SessionExpiredException.

java.net.ConnectException: Connection refused
    at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
    at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:589) ~[na:na]
    at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:839) ~[na:na]
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:342) ~[zookeeper-3.6.0.jar:3.6.0]
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1262) ~[zookeeper-3.6.0.jar:3.6.0]
020-09-12 20:09:06.733  INFO 14075 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn    

所以看来我的应用程序仍在尝试连接到localhost:2181上的zookeeper。有人可以告诉我我错过了什么吗?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...