VMware vRealize Automation 8.x (2022) — Question 10
Given an ApplicationContext containing three bean definitions of type Foo with bean ids foo1, foo2, and foo3, which three @Autowired scenarios are valid and will allow the ApplicationContext to initialize successfully? (Choose three.)
Answer options
- A. @Autowired public void setFoo (Foo foo) {…}
- B. @Autowired @Qualifier (“foo3”) Foo foo;
- C. @Autowired public void setFoo (@Qualifier (“foo1”) Foo foo) {…}
- D. @Autowired private Foo foo;
- E. @Autowired private Foo foo2;
- F. @Autowired public void setFoo(Foo foo2) {…}
Correct answer: B, C, E
Explanation
Option B is valid as it uses @Qualifier to specify the exact bean to inject, allowing the ApplicationContext to identify foo3. Option C is also valid as it uses @Qualifier for foo1, ensuring the correct bean is injected. Option E is valid because it directly injects foo2 without any ambiguity. The other options either lack qualifiers or do not specify a bean, which can lead to ambiguity or failure to inject.