spring-cloud-config: Retry for spring.config.import=configserver: declared in profile-specific application.properties does not work

Describe the bug

I’m trying to upgrade an spring boot/spring cloud config application to spring boot 2.4.2 and spring cloud 2020.0.1 to use the new spring.config.import property but having problem with the spring cloud config client configuration in combination with spring retry when the configuration is located in an profile-specific property file.

The application have the following two property files:

application.properties:
spring.config.import=optional:configserver:http://localhost:8888

application-fail.properties:

spring.config.import=configserver:http://localhost:8888
spring.cloud.config.fail-fast=true
spring.cloud.config.retry.max-attempts=15

When running without a spring config server., I’m observing the following behaviors:

When starting with the default profile, the application starts as expected with a log message like: Connect Timeout Exception on Url - http://localhost:8888. Will be trying the next url if available

When running with SPRING_PROFILES_ACTIVE=fail, the application terminates directly at startup with:

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
	at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:150)
	at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:86)
	at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:59)
	at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:102)

If the config in application-fail.properties is moved to application.properties, the application waits for the retry max-attempts before terminating as expected with:

java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
	at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.doLoad(ConfigServerConfigDataLoader.java:150)
	at org.springframework.cloud.config.client.ConfigClientRetryBootstrapper.lambda$null$2(ConfigClientRetryBootstrapper.java:58)
	at org.springframework.retry.support.RetryTemplate.doExecute(RetryTemplate.java:329)
	at org.springframework.retry.support.RetryTemplate.execute(RetryTemplate.java:209)
	at org.springframework.cloud.config.client.ConfigClientRetryBootstrapper.lambda$null$3(ConfigClientRetryBootstrapper.java:57)
	at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:83)
	at org.springframework.cloud.config.client.ConfigServerConfigDataLoader.load(ConfigServerConfigDataLoader.java:59)
	at org.springframework.boot.context.config.ConfigDataLoaders.load(ConfigDataLoaders.java:102)

Note the absence of org.springframework.retry.support.RetryTemplate in the first stack trace snippet.

Sample

I generated a spring initializer project with the above configuration that illustrate the behavior described above. It’s available at https://github.com/perlan/config-retry

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 21 (9 by maintainers)

Commits related to this issue

Most upvoted comments

this will work in application-<profile>.{properties|yaml}

spring.config.import=configserver:http://configserver.example.com?fail-fast=true&max-attempts=10&max-interval=1500&multiplier=1.2&initial-interval=1100"

@v1nc3n4 Thanks for the detailed explanation. I’m not exactly sure how to handle this one. I’ll add it to the list to chat with @philwebb about.