Spring Cloud 2022 Config Client无法连接到Config Server

6rqinv9w  于 2023-05-28  发布在  Spring
关注(0)|答案(1)|浏览(213)

运行Sping Boot v3.0.4、Spring v6.0.6、JDK1.17

客户端无法连接到在标准端口8888上运行的配置服务器。配置服务器上没有安全性。服务器的执行器端点可通过http://localhost:8888/config-server/health访问...
正如预期的那样,如果客户端设置为spring.cloud.config.fail-fast=false,那么客户端将启动。
值得注意的是,当我添加application-local.yml并将spring.config.import更改为我的主机名时,客户端会在本地配置文件中循环,失败,然后尝试默认值,然后很快失败。

服务器:

spring:
  application:
    name: config-server
  cloud:
    bus:
      enabled: true
      id: ${spring.application.name}
  rabbitmq:
    host: localhost
    port: 5672
    username: guest
    password: guest
  cloud:
    config:
      server:
        git:
          uri:  file:///c:\\projects\\my-configurations

server:
  port: 8888
  servlet:
    context-path: /${spring.application.name}
... Running with Spring Boot v3.0.4, Spring v6.0.6
... Tomcat started on port(s): 8888 (http) with context path '/my-config-server'
... Creating binder: rabbit
... Constructing binder child context for rabbit
... Caching the binder: rabbit
... declaring queue for inbound: springCloudBus.anonymous.j-rYOoG8QBeDzjd09_XQog, bound to: springCloudBus
... Attempting to connect to: [localhost:5672]
... Created new connection: rabbitConnectionFactory#5f3ddc86:0/SimpleConnection@147aceec [delegate=amqp://guest@127.0.0.1:5672/, localPort=64960]
... Channel 'rabbit-1425418950.springCloudBusInput.errors' has 1 subscriber(s).
... Channel 'rabbit-1425418950.springCloudBusInput.errors' has 2 subscriber(s).
... started bean 'inbound.springCloudBus.anonymous.j-rYOoG8QBeDzjd09_XQog'
... Started MyConfigApplication in 7.843 seconds (process running for 8.249)

服务器执行器端点是可访问的。

客户端POM:

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>
        <!-- CLOUD PROPERTY MANAGEMENT -->
        <!-- Spring Configuration Client -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <!-- Cloud Bus config refresh -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bus-amqp</artifactId>
            <version>${spring-cloud-starter-bus-amqp.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-webflux</artifactId>
        </dependency>

客户端应用.yml

spring:
  application:
    name: gdelt-ingest
import
  config:
    import: "optional:configserver:"

客户结果

... Starting application com.bar.gdelt.mapper.GdeltMapperApplication with URLs [file:/C:/projects/gdelt-mapper/target/classes/]
... Retry: count=0
... Retry: count=0
... Fetching config from server at : http://localhost:8888
... Checking for rethrow: count=1
... Retry: count=1
... Retry: count=1
... Fetching config from server at : http://localhost:8888
... Checking for rethrow: count=2
... Retry: count=2
... Retry: count=2
... Fetching config from server at : http://localhost:8888
... Checking for rethrow: count=3
... Retry failed last attempt: count=3
... Application run failed
org.springframework.cloud.config.client.ConfigClientFailFastException: Could not locate PropertySource and the fail fast property is set, failing: None of labels [] found
        at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:199)
        at org.springframework.cloud.config.client.ConfigClientRetryBootstrapper.lambda$initialize$0(ConfigClientRetryBootstrapper.java:
htrmnn0y

htrmnn0y1#

由于我在Config Server中指定了一个应用程序名称,因此它需要客户端中的完整URL。在测试配置服务器执行器端点时,我应该已经捕获了http://localhost:888/config-server/health

配置服务器

spring:
  application:
    name: config-server

客户端

spring:
  application:
    name: gdelt-mapper
    config:
      fail-fast: true
      retry:
        initial-interval: 1000
        max-attempts: 3
  config:
    import: "optional:configserver:http://localhost:8888/config-server"

相关问题