VMware vRealize Automation 8.x (2022) — Question 3
Which two statements are true concerning constructor injection? (Choose two.)
Answer options
- A. If there is only one constructor the @Autowired annotation is not required.
- B. Constructor injection only allows one value to be injected.
- C. Constructor injection is preferred over field injection to support unit testing.
- D. Construction injection can be used with multiple constructors without @Autowired annotation.
- E. Field injection is preferred over constructor injection from a unit testing standpoint.
Correct answer: A, C
Explanation
The correct answer, A, is accurate because when there is only one constructor in a class, Spring automatically uses it for dependency injection, making @Autowired unnecessary. Option C is also correct as constructor injection allows for easier testing through the provision of dependencies directly. Options B, D, and E are incorrect because constructor injection can handle multiple values through multiple parameters, it does require @Autowired for multiple constructors, and field injection is generally considered less favorable for unit testing due to tight coupling.