If a property @property.absent@
defined in application.properties
cannot be expanded (it is not defined in pom.xml
), the bound value is the literal @property.absent@
. Is there an easy way to override this with custom defaults (e.g. null), esp. in auto-configuration in conjunction with @ConfigurationProperties
?
Asked
Active
Viewed 316 times
1

zmeeagain
- 439
- 4
- 4
1 Answers
0
application.yml file:
test:
property: @property.absent@
Configuration properties class:
@ConfigurationProperties("test")
public class TestConfigurationProperties {
private String property = "your default value";
//Getters and Setters
}

Mykhailo Moskura
- 2,073
- 1
- 9
- 20
-
Yes, had tried that, but somehow hadn't worked. To make matters concrete, here's a stripped-down project illustrating this: [expansion](https://github.com/zmeeagain/expansion) – zmeeagain Apr 19 '20 at 20:33
-
You have not used '@Value' annotation For your purposes please use constant value in '@Configuration' properties , like private String absent = "Hello"; – Mykhailo Moskura Apr 19 '20 at 21:14
-
Yes, didn't add `@Value` in `ConfigurationProperties` as it does not work. Ideally I would like to combine the benefit of mapping complex nested config properties to source (using ConfigurationProperties) with defaults. – zmeeagain Apr 20 '20 at 11:15
-
In case of that try to assign default value like private String a = "default" – Mykhailo Moskura Apr 20 '20 at 11:24
-
Yes, had tried this too, this would work if the property were not there at all in `application.properties`. In this case however it's still defaulted to `@absent@`. – zmeeagain Apr 25 '20 at 15:26