hiexam
vmware · 2V0-7222 · Q603 · multiple_response · topic_1

Given an ApplicationContext containing three bean definitions of type Foo with bean ids foo1, foo2, and foo3, which thr…

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.)
  • 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) {…}
Explanation
A and D is not correct at all. I defined 3 beans definitions with those ids and in my service class used setter injection or simple Foo foo definition of Autowired-> gives error: Could not autowire. There is more than one bean of 'Foo' type. Beans: foo1 (MyConfiguration.java), foo2 (MyConfiguration.java), foo3 (MyConfiguration.java) Working cases per single case: B,C,E,F But not works all 4 together, C and F say the setFoo method name is already defined. So B, E, F will work -> but will inject only 2 beans, foo3 and foo2 -> foo2 in 2 places, but is at the end the same bean defined once through setter injection and second time through autowired filed injection. Or B, E, C will work -> will inject foo1, foo2, foo3 So the only correct answer to inject beans foo1,foo2,foo3 with working program is B, E, C.

Reference: examtopics_top_comment

Practice with progress tracking

Sign in to track wrong answers, get spaced-repetition reminders, and run timed exam mode.