Spring Boot Interview Question

What does the Autowired annotation do in Spring?

Updated 2026-07-10 · Beginner friendly
Quick answer

The Autowired annotation tells Spring to automatically inject a matching bean into a field, constructor, or setter. Spring finds a bean of the required type in its container and supplies it, so you do not create the dependency yourself. Modern Spring can inject through the constructor without Autowired when there is a single constructor.

How injection styles compare

// Constructor injection (preferred)
@Service
class OrderService {
    private final PaymentService payment;
    OrderService(PaymentService payment) { this.payment = payment; }
}

You can also autowire a field directly, but constructor injection is preferred because it makes dependencies visible, supports final fields, and is easy to test without Spring.

When types are ambiguous

If two beans match the same type, Spring cannot decide. You resolve this with the Qualifier annotation to name the exact bean, or by marking one bean as Primary.

In the interview

Say you prefer constructor injection and only reach for field injection rarely. Mentioning Qualifier and Primary for resolving multiple matching beans handles the natural follow up before it comes.

Want the full Spring Boot guide?

Read every Spring Boot concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the Spring Boot guide All Spring Boot questions