2V0-72.22PSE · Question #44
Which two options will inject the value of the daily.limit system property? (Choose two.)
The correct answer is C. @Value("$(daily.limit)") D. @Value("#{systemProperties['daily.limit']}"). Options C and D are correct because Spring's @Value supports two distinct injection syntaxes: property placeholder ${...} and Spring Expression Language (SpEL) #{...}. Option C (${daily.limit}) uses property placeholder syntax, which directly resolves system properties by their…
Question
Which two options will inject the value of the daily.limit system property? (Choose two.)
Options
- A@Value("#{daily.limit}")
- B@Value("$(systemProperties.daily.limit)")
- C@Value("$(daily.limit)")
- D@Value("#{systemProperties['daily.limit']}")
- E@Value("#{systemProperties.daily.limit}")
How the community answered
(30 responses)- A3% (1)
- B13% (4)
- C80% (24)
- E3% (1)
Explanation
Options C and D are correct because Spring's @Value supports two distinct injection syntaxes: property placeholder ${...} and Spring Expression Language (SpEL) #{...}. Option C (${daily.limit}) uses property placeholder syntax, which directly resolves system properties by their key name. Option D (#{systemProperties['daily.limit']}) uses SpEL to access the implicit systemProperties map with bracket notation, which is required because the key contains a dot character.
Why the distractors fail:
- A (
#{daily.limit}) - SpEL tries to evaluatedailyas an object and.limitas a property on it; there is no such bean, so it fails. - B (
${systemProperties.daily.limit}) - Property placeholder syntax doesn't support navigating objects with dot notation;${...}treats the entire string as a flat key lookup. - E (
#{systemProperties.daily.limit}) - SpEL dot notation callsgetDaily()on thesystemPropertiesmap, thengetLimit()on the result. Since the actual key is"daily.limit"(a single string with a dot in it), dot-notation navigation breaks; bracket notation['daily.limit']is required.
Memory tip: When the property key contains a dot (like daily.limit), bracket notation ['daily.limit'] is your only safe SpEL option - dots in SpEL mean "navigate into an object," not "part of a key name." And ${} vs #{} = property placeholder vs SpEL - a dollar sign fetches a flat key, a hash evaluates an expression.
Topics
Community Discussion
No community discussion yet for this question.