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

Spring Cloud Config Server无法从GitHub拉取配置文件求助

Spring Cloud Config Server从GitHub拉取配置超时问题

依赖配置

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.3.4</version>
    <relativePath/>
</parent>

<properties>
    <java.version>17</java.version>
    <spring-cloud.version>2023.0.2</spring-cloud.version>
</properties>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>${spring-cloud.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

配置文件

server:
  port: 8888

spring:
  application:
    name: ConfigServer

  cloud:
    config:
      server:
        git:
          uri: ${GITHUB_URI}
          username: ${GITHUB_USERNAME}
          password: ${GITHUB_PASSWORD}
          skip-ssl-validation: true
          clone-on-start: true
          default-label: main

logging:
  level:
    org.springframework.cloud.config.server: TRACE
    org.eclipse.jgit: TRACE

问题背景

已确认配置服务器可正常通过GitHub认证(修改认证信息会触发未授权异常),目标GitHub仓库仅含main分支,且仅有一个application.yml文件。

异常现象

  • 请求不存在的路径(如http://localhost:8888/safassdfa)会立即返回404;
  • 请求合法路径(如http://localhost:8888/default/application或http://localhost:8888/main/application.yml)会超时。

错误日志

2024-10-12T17:58:14.279+02:00  INFO 19170 --- [ConfigServer] [nio-8888-exec-6] o.s.c.c.c.ConfigServerConfigDataLoader   : URL请求异常 - http://localhost:8888:org.springframework.web.client.ResourceAccessException: GET请求"http://localhost:8888/application/default"发生I/O错误:读取超时。若有备用URL将尝试下一个
2024-10-12T17:58:14.279+02:00  WARN 19170 --- [ConfigServer] [nio-8888-exec-6] o.s.c.c.c.ConfigServerConfigDataLoader   : 无法定位属性源([ConfigServerConfigDataResource@2e510fa3 uris = array<String>['http://localhost:8888'], optional = true, profiles = 'default']): GET请求"http://localhost:8888/application/default"发生I/O错误:读取超时

解决方案

问题根源是Spring Cloud Config Server默认会启用Config Client功能,启动时尝试从自身(配置服务器)拉取配置,形成循环请求导致超时。可通过以下两种方式解决:

  1. 配置文件禁用客户端功能
    在配置文件中添加如下配置:
spring:
  cloud:
    config:
      enabled: false  # 禁用Config Client自动配置,避免循环调用
  1. 启动类排除自动配置类
    在启动类上排除相关自动配置组件:
@SpringBootApplication(exclude = ConfigServerConfigDataAutoConfiguration.class)
@EnableConfigServer
public class ConfigServerApplication {
    public static void main(String[] args) {
        SpringApplication.run(ConfigServerApplication.class, args);
    }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 06:25:12