@Value annotation refers to properties or command line using ${propertyName} syntax.

If you try to inject a property that’s not available in application context (for example @Value(“${owner}”)), then Spring will throw *IllegalArgumentException: Could not resolve placeholder ‘owner’ in string value “${owner}”*.

To inject a default value you can pass it after property name, like so: @Value(“${owner:0}”).

The problem is when you want to inject null as default value. If you try to use @Value(“${owner:null}”) then Spring will treat it literally and inject *”null”* string, which can lead to unexpected results! Here passing no owner argument will initialize it with “null” string and won’t return No owner as expected. Yay!

To inject null as default value you have to use Spring Expression Language like so: @Value(“${owner:#{null}}”). Now Spring Framework will inject null reference not a “null” string value: