Is your feature request related to a problem? Please describe. As per the docs:
If you expect that the config server may occasionally be unavailable
when your application starts, you can make it keep trying after a failure.
We want to use that, since our config server take some time to be up. But, we also want to use the application.yaml
, if the server is not reachable (basically, the behaviour of spring.cloud.config.fail-fast: false
).
Can we have the "best of both worlds"?
Describe the solution you'd like
When I have the spring.cloud.config.fail-fast: false
set and added spring-retry
and spring-boot-starter-aop
to my classpath, I want to have an additional flag to indicate, that the application should fall back default values from the application.yaml
Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.
Additional context In the ConfigServicePropertySourceLocator is the code that checks for the fail-fast propery.
Comment From: ryanjbaxter
Are you using spring.config.import=optional:configserver
?
Comment From: Gregsen
Hey,
I am using the "old" setup: I have a bootstrap.yaml
spring:
application:
name: my-application
cloud:
config:
uri: http://localhost:8888
server:
bootstrap: false
fail-fast: false
and I am using version 2.0.0.M9
of spring-cloud-config. The application is on spring boot 2.6.6
and java 11
.
Would moving to spring.config.import=optional:configserver
make it possible to have a retry and a fallback?
Comment From: ryanjbaxter
I believe it would, see the NOTE
in this section of our documentation
https://docs.spring.io/spring-cloud-config/docs/4.0.3/reference/html/#config-client-fail-fast
Spring Cloud Config 2.0.0.M9 is not supported any longer, I would at least upgrade to Spring Cloud 2021.0.7.
Comment From: Gregsen
Hey,
I tried your suggestion with a "newer" application of ours. It's spring boot 2.7.0
application with spring-cloud-dependencies 2021.0.7
.
The issue is basically the same. While the application now keeps running, its marked as failed and will stop all listeners and endpoints (going to Application availability state ReadinessState changed to REFUSING_TRAFFIC
).
The Exception this time is different:
org.springframework.cloud.config.client.ConfigClientFailFastException: Could not locate PropertySource and the fail fast property is set, failing
at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:197) ~[spring-cloud-config-client-3.1.3.jar:3.1.3]
However, the reason seems similar: If fail-fast
is enabled, the application will not fall back to the default values in the application.yaml
, but just stop with an error.
Ideally, there would be an option to prevent the exception and just continue running.
Comment From: ryanjbaxter
What if you remove the fail-fast
property and just set `spring.config.import=optional:configserver:"? If the client can't reach the config server in that case it should just continue on.
Comment From: ryanjbaxter
If fail-fast is set to true it means to fail on startup if it can't reach the config server. You want the application to startup and use application.yaml
if it can't reach the config server so fail-fast needs to be false and/or you need to add optional to the config.import statement.