我只发现其他 1 个地方报告了此问题,但没有解决方案:https://github.com/spring-cloud/spring-cloud-config/issues/2052
我是2021年0月3日。当使用 spring.config.import 定义默认 localhost:8888 以外的任何内容时,它会调用我指定的服务器,然后调用 localhost:8888,这会失败并且应用程序将无法启动。
应用程序属性:
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>
似乎我的问题是尝试在与我的配置服务器相同的 spring.config.import 配置中导入访问我的服务器所需的 aws 密钥。所以我只需要以不同的方式注入用户名密码。我以为我在没有导入的情况下进行了测试,但我必须擦除我的目标目录并重新打包才能使其工作。
自从 Spring Boot 的某个版本(我不太记得了,可能是 2.7)以来,
bootstrap.properties
机制已被弃用。不过,为了恢复对此功能的支持,我们提供了一个启动器:spring-cloud-starter-bootstrap
。此启动器会导致所描述的行为,并且可能是如下所述的原因:
https://github.com/spring-cloud/spring-cloud-config/issues/2052
即使不直接添加,它也可能作为其他库的临时依赖项加载。此类库的示例之一是
log4j-spring-cloud-config-client
,如下所述: