Skip to content
Sharp

Dependency Injection · interview question

In Spring Boot, what is the effect of marking a bean as @Primary?

Multiple choiceMediumchapter-9-curatedpremiumdependency-injectionconstructor-vs-field-injection
Choose one answer
Answer and explanation

Correct answer

A. It is chosen over other beans when multiple candidates are present.

Why

The @Primary annotation indicates that the annotated bean should be given preference when multiple candidates are available for autowiring, simplifying configuration when dealing with multiple similar beans.

Test yourself on Dependency Injection

A free test with instant, explained results. No account needed.

Start free test
All Dependency Injection questions →