In a spring project, I'd like to create a LocalDate
from an @Autowired
constructor parameter whose value is in a .properties
file. Two things I'd like to do:
1. If the property file contains the property my.date
, the parameter should be created by parsing the property value
When the property is set, and when I use the following:
@DateTimeFormat(pattern = "yyyy-MM-dd") @Value("${my.date}") LocalDate myDate,
...
I get this error: java.lang.IllegalStateException: Cannot convert value of type 'java.lang.String' to required type 'java.time.LocalDate': no matching editors or conversion strategy found
I have also used the iso = ...
to use an ISO date with the same result.
2. If the property is not in the properties file, the parameter should be created using LocalDate.now()
I tried using a default value as such:
@Value("${my.date:#{T(java.time.LocalDate).now()}}") LocalDate myDate,
...
But I get the same error.
Forgive my ignorance with Spring, but how can I achieve the two objectives here?