Add Default Value To Spring Boot @Value Annotation

Asked By 0 points N/A Posted on -
qa-featured

I am trying to add default values to spring boot variable and various value notations but don’t know how to. How can I add a default value to spring boot in its @value notation?

SHARE
Answered By 30 points N/A #318631

Add Default Value To Spring Boot @Value Annotation

qa-featured

To inject a property value in spring bean you have to use

@Value(“${property_name}”)

And to assign a default value to the decided property value we have to use the line:

@Value(“${property_name:default_value}”)

And if you wish to provide null value as default then add

@Value(“${property_name:#{null}}”)

Example:

Related Questions