question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
spencergibbcommented, May 26, 2021

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"
2reactions
spencergibbcommented, Mar 30, 2021

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

5 Observations on Spring Boot's Loading Precedence for ...
Sharing my experience on the order of precedence for properties files in Spring Boot applications when using Spring Cloud Config and Spring Profiles....
Read more >
Could Not Locate Propertysource And The Fail Fast Property ...
Ask questionsRetry for spring.config.importconfigserver: declared in profilespecific application.properties does not work. Describe the bug.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found