nerdexam
Broadcom-VMware

2V0-72.22PSE · Question #86

Which two ways to access the properties defined in an application.properties or application.yml file are correct? (Choose two.)

The correct answer is A. Through the getProperty() method of the Spring Environment object. B. Through a constructor parameter annotated with @Value. A and B are correct because Spring provides two idiomatic mechanisms for reading application.properties/application.yml values: the Environment object (injected as a bean) exposes a getProperty("key") method that reads from any registered PropertySource, and @Value("${key}") on…

Core Spring

Question

Which two ways to access the properties defined in an application.properties or application.yml file are correct? (Choose two.)

Options

  • AThrough the getProperty() method of the Spring Environment object.
  • BThrough a constructor parameter annotated with @Value.
  • CThrough the getProperty() method of a Properties object.
  • DThrough the getProperty() method of an ApplicationContext object.
  • EThrough a constructor parameter annotated with @Property.

How the community answered

(54 responses)
  • A
    78% (42)
  • C
    11% (6)
  • D
    4% (2)
  • E
    7% (4)

Explanation

A and B are correct because Spring provides two idiomatic mechanisms for reading application.properties/application.yml values: the Environment object (injected as a bean) exposes a getProperty("key") method that reads from any registered PropertySource, and @Value("${key}") on a constructor parameter (or field) lets Spring inject the value directly at wiring time.

Why the distractors are wrong:

  • C - java.util.Properties is a plain Java class unaware of the Spring context; its getProperty() reads from that specific Properties instance, not from Spring's unified property sources.
  • D - ApplicationContext does not expose a getProperty() method; it inherits from EnvironmentCapable and gives you access to the Environment object, but you must then call getProperty() on that Environment, not on the context itself.
  • E - @Property does not exist in Spring; the real annotation is @Value. This is a classic trap using a plausible-sounding but invented name.

Memory tip: Think "Spring gives you two ports into properties - the Environment door (programmatic) and the @Value door (declarative)." If a choice says ApplicationContext.getProperty() or invents a fake annotation like @Property, it's wrong.

Topics

#Property injection#@Value annotation#Spring Environment#Configuration management

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice