0

In my application.properties file I would like to have an optional value. Such as spring.datasource.url=${value} but optional Is this possible?

1 Answers1

0

You can define a property as "optional" by giving it a default value where you inject it.

For example:

@Value("${spring.datasource.url:null}")
private String springDatasourceURL;
DwB
  • 37,124
  • 11
  • 56
  • 82
  • To my knowledge, no. – DwB May 08 '19 at 19:38
  • check out this: https://stackoverflow.com/questions/2513484/is-there-a-way-to-specify-a-default-property-value-in-spring-xml It may be what you want. – DwB May 08 '19 at 19:39
  • based on that question, it looks like defaults can be set in xml configuration as well. – DwB May 08 '19 at 19:40
  • uncheck correct answer if 2513484 answers your question and we can mark this as a duplicate. – DwB May 08 '19 at 19:41