spring-cloud / spring-cloud-zookeeper

Spring Cloud Zookeeper
http://cloud.spring.io/spring-cloud-zookeeper/
Apache License 2.0
556 stars 413 forks source link

connect-string doesn't work in application.yml #176

Closed wenfei3 closed 6 years ago

wenfei3 commented 6 years ago

Hello , I have met a problem about the application.yml when I was building a service discovery with spring-cloud-zookeeper.

pom

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>1.5.13.RELEASE</version>
    </parent>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
        <!-- Support PATCH -->
        <dependency>
            <groupId>io.github.openfeign</groupId>
            <artifactId>feign-httpclient</artifactId>
            <version>9.5.0</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-zookeeper-all</artifactId>
        </dependency>
    </dependencies>

application.yml

server:
  port: 8002
spring:
  application:
    name: consumer
  cloud:
    zookeeper:
      connect-string: localhost:2222
      enabled: false

exception

2018-09-13 17:51:13.657  INFO 35987 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn          : Opening socket connection to server localhost/127.0.0.1:2181. Will not attempt to authenticate using SASL (unknown error)
2018-09-13 17:51:13.658  WARN 35987 --- [localhost:2181)] org.apache.zookeeper.ClientCnxn          : Session 0x0 for server null, unexpected error, closing socket connection and attempting reconnect

java.net.ConnectException: Connection refused
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.8.0_144]
    at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:717) ~[na:1.8.0_144]
    at org.apache.zookeeper.ClientCnxnSocketNIO.doTransport(ClientCnxnSocketNIO.java:361) ~[zookeeper-3.4.8.jar:3.4.8--1]
    at org.apache.zookeeper.ClientCnxn$SendThread.run(ClientCnxn.java:1141) ~[zookeeper-3.4.8.jar:3.4.8--1]

the app connect to localhost:2181,but not localhost:2222.It will work If I change the yml file's name from application.yml to bootstrap.yml .I guess the zk client start time is earlier than the application.yml be read. So do I have to add a bootstart.yml to my project?

wenfei3 commented 6 years ago

Well,I found a phenomenon . If I use

<dependency>
    <groupId>org.springframework.cloud</groupId>
   <! -- <artifactId>spring-cloud-starter-zookeeper-all</artifactId> -- >
    <artifactId>spring-cloud-starter-zookeeper-discovery</artifactId>
</dependency>

in my pom,the application.yml will work.I know the reason of my problem. spring-cloud-starter-zookeeper-all will introduce the zk config, zk config must use bootstrap.yml. Is it right?

spencergibb commented 6 years ago

That is correct