Spring Cloud Config Client tries localhost:8888 in addition to my specified server location

738 Views Asked by At

I have only found this issue reported in 1 other place, but no resolution: https://github.com/spring-cloud/spring-cloud-config/issues/2052

I'm on 2021.0.3. When defining anything other than the default localhost:8888 using spring.config.import, it calls my specified server, then it calls localhost:8888, which fails and the application will not start up.

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}

Startup logs:

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

There are 2 best solutions below

0
Keller Martin On

Seems my issue was trying to import the aws secret needed to access my server in the same spring.config.import config as my config server. So I'll just need to inject the username password a different way. I thought I tested without both imports, but I had to wipe my target directory and repackage for it to work.

0
Rafi On

Since some version of Spring Boot (I don't remember exactly, possibly 2.7) the bootstrap.properties mechanism has been deprecated. However to bring back support for this feature a starter has been provided: spring-cloud-starter-bootstrap. This starter causes described behavior and may be the reason as described in:

https://github.com/spring-cloud/spring-cloud-config/issues/2052

Even if not directly added it may be loaded as transient dependency of some other library. One of the examples of such library is log4j-spring-cloud-config-client as described in:

https://github.com/apache/logging-log4j2/issues/2157