2V0-72.22PSE · Question #99
Which two statements are correct regarding the differences between @ConfigurationProperties and @Value? (Choose two.)
The correct answer is C. @ConfigurationProperties is preferable over @Value when type-safety during property binding is E. @ConfigurationProperties supports relaxed binding of properties, but not property binding through. C is correct because @ConfigurationProperties binds an entire group of properties to a typed POJO, giving you compile-time type safety, validation support (@Validated), and IDE auto-completion - making it the preferred choice over @Value when working with structured…
Question
Which two statements are correct regarding the differences between @ConfigurationProperties and @Value? (Choose two.)
Options
- A@Value must be used for environment variables, as @ConfigurationProperties cannot access the
- B@Value supports relaxed binding of properties, but not property binding through SpEL.
- C@ConfigurationProperties is preferable over @Value when type-safety during property binding is
- D@ConfigurationProperties only bind properties from .properties files, not from .yml files.
- E@ConfigurationProperties supports relaxed binding of properties, but not property binding through
How the community answered
(40 responses)- A10% (4)
- B5% (2)
- C83% (33)
- D3% (1)
Explanation
C is correct because @ConfigurationProperties binds an entire group of properties to a typed POJO, giving you compile-time type safety, validation support (@Validated), and IDE auto-completion - making it the preferred choice over @Value when working with structured configuration.
E is correct because @ConfigurationProperties supports relaxed binding (e.g., my.prop, MY_PROP, my-prop, and myProp all map to the same field), but it does not support SpEL expressions. @Value is the opposite - it supports SpEL (e.g., @Value("#{systemProperties['user.home']}")) but does not support relaxed binding.
Why the distractors are wrong:
- A:
@ConfigurationPropertiescan access environment variables - both annotations read from the sameEnvironmentabstraction. - B: This has the capabilities backwards - relaxed binding belongs to
@ConfigurationProperties, and SpEL belongs to@Value. - D:
@ConfigurationPropertiesworks with both.propertiesand.ymlfiles; it is not limited to one format.
Memory tip: Think of the split as "Config = Class" vs "Value = Variable" - @ConfigurationProperties binds a class (type-safe, relaxed), while @Value injects a single variable (SpEL-capable, strict). Their SpEL/relaxed-binding capabilities are mutually exclusive and swapped.
Topics
Community Discussion
No community discussion yet for this question.