Is it possible to use @Value annotation with a variable as default?
I have a variable processingYear , I would like to read from properties, If it cannot read from properties, I would like to assign the current year into the variable.
@Value("${processing_year:2021}")
int processingYear;
With the code specific above, I can read the processingYear from the properties file, and assign value to it, if reading from properties failed, the variable will be set to 2021.
However, I do not see a way to assign the current year as a default variable currentYear. Following is what I imagined and would like to see if there is anything to assign a default variable to it.
LocalDate date = LocalDate.now();
Locale locale = Locale.US;
int currentYear = Integer.parseInt(date.format(DateTimeFormatter.ofPattern("yyyy",locale)));
@Value("${process_year:currentYear}")
int processingYear;