Reputation: 16525
In this article we can see how to generate random properties in application.properties
. Is there also some way how to generate some other properties like current year using java code in application.properties
?
I tried this:
config.current-year=${LocalDate.now.getYear}
but it throws exception:
Caused by: java.lang.NumberFormatException: For input string: "${LocalDate.now.getYear}"
UPDATE:
after iamrajshah answer I see random represent class RandomValuePropertySource
which is loaded in this way:
protected void addPropertySources(ConfigurableEnvironment environment,
ResourceLoader resourceLoader) {
RandomValuePropertySource.addToEnvironment(environment);
new Loader(environment, resourceLoader).load();
}
so all I need is just to override (Idk now) this function and add there my class which I can use.
Upvotes: 1
Views: 979
Reputation: 979
You can check this out
application.properties
are like registering similar to *.xml
in previous version of spring.
Spring boot provides RandomValuePropertySource
which used to generate values.
NOT any other classes supports in this file.
Upvotes: 1