Question 1
Two beans of type PaymentService are defined. What happens when application code calls context.getBean(PaymentService.class)?
A. It returns whichever bean was defined first
Spring does not silently pick the first-defined candidate; an ambiguous single-type lookup is treated as an error, not resolved by definition order.
B. It throws NoUniqueBeanDefinitionException unless one candidate is marked @PrimaryCorrect answer
When multiple candidates match a single-type lookup the resolution is ambiguous, so the container throws NoUniqueBeanDefinitionException; marking one candidate @Primary (or selecting by name/qualifier) disambiguates it (Spring Framework 5.3 Reference — Autowiring & @Primary).
C. It returns a List containing both beans
A single-type getBean call is expected to return one instance, not collapse multiple matches into a List; retrieving all matches is a different, collection-style lookup.
D. It returns null because the lookup is ambiguous
Spring signals the ambiguity by throwing an exception rather than quietly returning null.
Explanation
Requesting a single bean by type when more than one candidate matches is ambiguous, and Spring surfaces that ambiguity by throwing NoUniqueBeanDefinitionException rather than guessing. Designating one candidate as primary, or selecting by name or qualifier, tells the container which one to return. It does not default to the first definition, hand back null, or bundle the matches into a collection for a single-type request.