简体   繁体   中英

How to generate current year in spring boot properties

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM