Spring-boot 3 onfig 服务器客户端尝试 localhost:8888,即使 URL 已正确配置

问题描述 投票:0回答:1

在 stack-overflow 中也提出了同样的问题,但没有找到正确的解决方案。我的应用程序中有以下配置。如果其他应用程序在 8888 上运行,它会抱怨同样的问题,甚至卡住。

有人有办法避免这种情况吗?

日志:

2024-03-20 14:32:22.078  INFO 18756 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2024-03-20 14:32:22.110  INFO 18756 --- [           main] c.c.c.ConfigServicePropertySourceLocator : Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available

依赖关系:

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-config</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-bootstrap</artifactId>
        </dependency>

应用程序.yml

spring:
  application:
    name: my-app
  profiles:
    active: stage

---
spring:
  cloud:
    config:
      label: dev
  config:
    import: configserver:http://myconfig:5232
    activate:
      on-profile: stage

---
spring:
  cloud:
    config:
      label: prod
  config:
    import: optional:configserver:http://config.abc.com
    activate:
      on-profile: prod

---
spring spring-boot spring-cloud-config
1个回答
0
投票

您正在使用

spring-cloud-starter-bootstrap
,它启用 旧配置处理。但是,在您的属性中,您正在使用配置配置处理的新方法。

所以你有两个选择:

  1. 删除

    spring-cloud-starter-bootstrap

  2. 使用旧版配置处理,这意味着您需要创建一个

    bootstrap.properties
    bootstrap.yml
    文件,其中包含:

    spring:
      application:
        name: my-app
      cloud:
        config:
          uri: http://myconfig:5232
    
© www.soinside.com 2019 - 2024. All rights reserved.