Reputation: 35557
I have below implementation currently working in spring boot 2.3. But when I migrate the same to spring boot 2.4. properties not reading from config server.
Code
@ConditionalOnProperty({"app.xzy.hosts"})
public class clientConfig {
// implementation
}
bootstrap.yml
spring:
cloud:
config:
uri: http://main-config-server.com
username: user
password: pass
fail-fast: true
application.yml
app:
xyz:
hosts: ${app.main.config.hosts}
application.yml in config server
app:
main:
config
hosts: http://myhost.com
This implementation is working fine in spring boot 2.3. But after the upgrade to spring boot 2.4 this giving below error in the startup.
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'app.xzy.hosts' in value "${app.main.config.hosts}"
at org.springframework.util.PropertyPlaceholderHelper.parseStringValue(PropertyPlaceholderHelper.java:178)
at org.springframework.util.PropertyPlaceholderHelper.replacePlaceholders(PropertyPlaceholderHelper.java:124)
at org.springframework.core.env.AbstractPropertyResolver.doResolvePlaceholders(AbstractPropertyResolver.java:239)
at org.springframework.core.env.AbstractPropertyResolver.resolveRequiredPlaceholders(AbstractPropertyResolver.java:210)
Upvotes: 1
Views: 961
Reputation: 35557
Finally figured out the issue.
bootstrap.yml file is no longer enabled by default. You need enable it by adding new dependency in spring cloud 2020.0.0 and it solved my issue.
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>
Reference: https://spring.io/blog/2020/10/07/spring-cloud-2020-0-0-m4-aka-ilford-is-available
Upvotes: 2