Reputation: 61
PropertyLoader class does not load the default value for "testValue" from application.yml
@ConfigurationProperties(prefix="my-property")
@Component
public class PropertyLoader {
String testValue;
public String getTestValue() {
return testValue;
}
public void setTestValue(String testValue) {
this.testValue = testValue;
}
}
application.yml
spring:
profiles:
active: default
my-property:
testValue: random
Upvotes: 0
Views: 896
Reputation: 61
Answering my on question as I figured it out after spending some time on it. Never set active profile in application.yml, in my case someone added active profile to default, as soon as the spring property loader sees the spring.profiles.active it searches for application-{avtive-profile}.yml, in my case application-default.yml since it does not find a file by that name it does not load the default values from application.yml
Upvotes: 0
Reputation: 4098
You should use @Value(„${testValue}“)
over testValue field.
https://www.baeldung.com/spring-value-annotation
Upvotes: 1