springspring-bootspring-cloud-config

Spring-boot 3 onfig server client tries localhost:8888 even if URLs are properly configured


The same question has been asked in stack-overflow, but no proper solution was been found. I have the following configurations in my app. It complains about the same issue and even it stuck, if some other app runs on 8888.

Does any body has answers to avoid this?

Logs:

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

Dependencies:

        <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>

application.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

---

Solution

  • You're using spring-cloud-starter-bootstrap, which enables legacy configuration processing. However, in your properties you're using the new way of configuring the configuration processing.

    So you have two choices:

    1. Remove spring-cloud-starter-bootstrap.

    2. Use the legacy configuration processing, which means you need to create a bootstrap.properties or bootstrap.yml file containing:

      spring:
        application:
          name: my-app
        cloud:
          config:
            uri: http://myconfig:5232