You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Cloud Config Client指定服务器后仍访问localhost:8888致启动失败

问题描述

使用Spring Cloud 2021.0.3版本,通过spring.config.import指定了非默认的Config Server地址https://my.server.com,客户端成功从该地址获取配置后,却又尝试访问默认地址localhost:8888,出现连接超时,最终导致应用启动失败。目前仅在同类GitHub问题中发现相似情况,但未找到有效解决方案。

配置文件(application.properties)

spring.application.name=msgw_application
spring.config.import=aws-secretsmanager:${ENVIRONMENT}/secret/path,configserver:https://my.server.com
spring.cloud.config.label=${CONFIGURATION_GIT_BRANCH}
spring.cloud.config.username=${username}
spring.cloud.config.password=${password}

启动日志

2022-09-01 07:50:58.763 |  | restartedMain | INFO | Fetching config from server at : https://my.server.com | org.springframework.cloud.config.client.ConfigServerConfigDataLoader | logTo | 255 |
2022-09-01 08:16:13.903 |  | restartedMain | INFO | Located environment: name=msgw/application, profiles=[dev], label=prod, version=401ea4bb26f13d49602a30e20997dff088d62934, state=null | org.springframework.cloud.config.client.ConfigServerConfigDataLoader | logTo | 255 |
2022-09-01 07:50:58.763 |  | restartedMain | INFO | Loading secrets from AWS Secret Manager secret with name: dev/secret/path, optional: false | io.awspring.cloud.secretsmanager.AwsSecretsManagerPropertySources | logTo | 255 |
2022-09-01 07:50:58.763 |  | restartedMain | INFO | Fetching config from server at : http://localhost:8888 | org.springframework.cloud.config.client.ConfigServerConfigDataLoader | logTo | 255 |
2022-09-01 07:50:58.763 |  | restartedMain | INFO | Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available | org.springframework.cloud.config.client.ConfigServerConfigDataLoader | logTo | 255 |
2022-09-01 07:50:58.764 |  | restartedMain | INFO | Fetching config from server at : http://localhost:8888 | org.springframework.cloud.config.client.ConfigServerConfigDataLoader | logTo | 255 |
2022-09-01 07:50:58.764 |  | restartedMain | INFO | Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available | org.springframework.cloud.config.client.ConfigServerConfigDataLoader | logTo | 255 |
2022-09-01 07:50:58.793 |  | restartedMain | ERROR | Application run failed

POM依赖

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>2021.0.3</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>
...
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-starter-config</artifactId>
</dependency>
解决方案尝试

1. 关闭默认Config Server自动触发逻辑

在配置文件中添加:

spring.cloud.config.enabled=false

该配置会禁用客户端自动连接默认Config Server的行为,仅使用spring.config.import中指定的地址加载配置。

2. 排除Config Server自动配置类

在应用启动类上添加排除配置:

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

避免框架自动加载默认的Config Server配置逻辑。

3. 升级Spring Cloud版本

该问题属于版本已知bug,尝试升级到2021.0.4及以上版本,官方在后续版本中修复了重复请求默认地址的问题。

4. 检查配置加载优先级

确保spring.config.import的配置未被其他配置源覆盖,比如环境变量、命令行参数等。可以通过spring.config.import=configserver:https://my.server.com,optional:false明确标记该配置为必填,避免后续加载逻辑触发默认地址。

内容的提问来源于stack exchange,提问作者Keller Martin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 21:06:16