nerdexam
Broadcom-VMware

2V0-72.22PSE · Question #91

Which two mechanisms of autowiring a dependency when multiple beans match the dependency's type are correct? (Choose two.)

The correct answer is A. Use of @Qualifier annotation on the class and @Autowired annotation either on a field or setter D. Use of @Qualifier and @Autowired annotations together on a field. @Qualifier on the class (A) and @Qualifier + @Autowired on a field (D) are the two correct mechanisms. Option A represents qualifying at the bean definition side - placing @Qualifier on the bean's class to label it, then using @Autowired alone on the injection point (field or…

Core Spring

Question

Which two mechanisms of autowiring a dependency when multiple beans match the dependency's type are correct? (Choose two.)

Options

  • AUse of @Qualifier annotation on the class and @Autowired annotation either on a field or setter
  • BUse of @Qualifier and @Autowired annotations together with setter methods.
  • CUse of @Qualifier annotation only with setter methods (@Autowired is optional for setters).
  • DUse of @Qualifier and @Autowired annotations together on a field.
  • EUse of @Qualifier annotation only on a field (@Autowired is optional for fields).

How the community answered

(43 responses)
  • A
    74% (32)
  • B
    5% (2)
  • C
    14% (6)
  • E
    7% (3)

Explanation

@Qualifier on the class (A) and @Qualifier + @Autowired on a field (D) are the two correct mechanisms. Option A represents qualifying at the bean definition side - placing @Qualifier on the bean's class to label it, then using @Autowired alone on the injection point (field or setter) to let Spring match that qualifier. Option D represents qualifying at the injection point - placing both @Qualifier and @Autowired together on a field, which is the most common pattern for disambiguating multiple matching beans.

Why the distractors are wrong:

  • B is incorrect because using @Qualifier + @Autowired on a setter is technically valid Spring behavior, but the question specifically asks for two distinct mechanisms - B describes the same injection-point mechanism as D, just on a setter, making it redundant and therefore not a correct answer choice here.
  • C is incorrect because @Autowired is not optional on setter methods - @Qualifier alone won't trigger injection.
  • E is incorrect for the same reason - @Qualifier alone on a field does nothing; @Autowired (or @Inject) is required to signal Spring to perform injection.

Memory tip: Think of it as two sides of a bridge - you can stamp the qualifier on the bean class (source side, Option A) or stamp it at the injection point on a field (destination side, Option D). Either way, @Autowired is always required at the injection side to trigger the wiring.

Topics

#@Qualifier annotation#@Autowired annotation#Dependency injection#Bean disambiguation

Community Discussion

No community discussion yet for this question.

Full 2V0-72.22PSE Practice