配置服务器未在 consul 首次设置中被发现

Config server not getting discovered in a consul first setup

我正在使用 consul 优先设置。为此,我正在使用 consul docker 镜像,端口 8500 映射到 8500,因此我可以在本地集 up.I 上成功使用它,可以在 http://localhost:8500 访问 consul。

我对 config 服务器进行了以下配置 - pom.xml

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-consul-discovery</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Dalston.RC1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

Application.yml

server:
   port: 8888
spring:
   cloud:
     config:
       server:
         git:
           uri: https://github.com/xxxxxx/spring-config-repo.git
consul:
  host: consul
  port: 8500
  enabled: true
  discovery:
    enabled: true
    register: true
    service-name: configservice

bootstrap.yml

spring:
   application:
     name: config-server

ConfigServerApplication.java

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

当我运行这个jar,就成功了。我可以在 consul ui 中看到配置服务器。 以下是从 consul-

看到的配置服务器的详细信息
Request - http://localhost:8500/v1/catalog/services
Response - 
{
"configservice": [],
"consul": []
}

Request - http://localhost:8500/v1/catalog/service/configservice
Response - 
[
 {
    "ID": "f6ac953c-07b9-4097-974e-3ea9cd39bec2",
    "Node": "a0954c644062",
    "Address": "127.0.0.1",
    "TaggedAddresses": {
        "lan": "127.0.0.1",
        "wan": "127.0.0.1"
    },
    "NodeMeta": {},
    "ServiceID": "config-server-8888",
    "ServiceName": "configservice",
    "ServiceTags": [],
    "ServiceAddress": "10.0.0.158",
    "ServicePort": 8888,
    "ServiceEnableTagOverride": false,
    "CreateIndex": 15,
    "ModifyIndex": 15
 }
]

我也可以使用这个 uri-

访问配置服务器
http://localhost:8888/configclient/default

我的客户端应用程序使用配置中的属性 server.My 我的理解是,当我 运行 这个 jar 时,它将联系 consul 并从那里获取配置服务器信息,并通过以下方式填充属性从给定的 git uri 中获取它。

以下是有关客户的详细信息 - pom.xml

    <dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-consul-all</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-starter-config</artifactId>
    </dependency>
</dependencies>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Dalston.RC1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

bootstrap.yml

spring:
   application:
      name: myservice
cloud:
  config:
    fail-fast: true
    retry:
      max-attempts: 20
      initial-interval: 3000
   enabled: true
   discovery:
     enabled: true
     service-id: configserver
consul:
  host: localhost
  port: 8500
  discovery:
    enabled: true
    register: true
    service-name: myservice

application.yml

server:
   port: 8081

MyServiceApplication.java

@EnableDiscoveryClient
@SpringBootApplication
public class MyServiceApplication {

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

但是在这个 jar 的启动过程中,它无法找到配置服务器,而是退回到默认的 uri 。 这是相关的启动日志部分

2017-03-28 00:40:20.407  WARN 99123 --- [           main]  lientConfigServiceBootstrapConfiguration : No instances found of  configserver (configserver)


2017-03-28 00:40:20.551  INFO 99123 --- [           main]  b.c.PropertySourceBootstrapConfiguration : Located property source:   CompositePropertySource [name='consul', propertySources= . [ConsulPropertySource [name='config/myservice/'],   ConsulPropertySource [name='config/application/']]]
2017-03-28 00:40:20.587  INFO 99123 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at: http://localhost:8888
2017-03-28 00:40:21.831  INFO 99123 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=myservice, profiles=[default], label=null, version=null, state=null
2017-03-28 00:40:21.832  INFO 99123 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='https://github.com/xxxxx/spring-config-repo.git/myservice.yml'], MapPropertySource [name='https://github.com/xxxxx/spring-config-repo.git/application.yml']]]
2017-03-28 00:40:21.841  INFO 99123 --- [           main] c.h.MyServiceApplication       : No active profile set, falling back to default profiles: default 

我从各种示例中修改了很多不同的选项,例如

有人可以指出我可能遗漏了什么吗? 任何指向可以访问 consul、configserver 和 client 的正确 application/bootstrap 文件的工作示例的指针都是最有帮助的。

PS:对于问题中的信息过载,我深表歉意。其中一些可能不相关,但我想提供尽可能多的信息,以便有人可以发现他们以前遇到过的东西。

您正在尝试查找 configserver,但它被注册为 configservice