Spring Boot

Spring Core - IoC & DI

Inversion of Control, Dependency Injection, annotations (@Component, @Autowired, @Bean), scopes, bean lifecycle

22 interview questions·
Junior
1

What is Inversion of Control (IoC) in Spring?

Answer

IoC is a principle where the Spring framework manages object creation and lifecycle, rather than the developer. This reverses the traditional control flow where application code directly instantiates its dependencies. Spring uses an IoC container to manage beans and their dependencies declaratively.

2

What is a bean in Spring?

Answer

A bean is an object managed by the Spring IoC container. It is instantiated, configured and assembled by Spring according to configuration metadata (annotations, XML or Java config). Beans are the core of a Spring application and benefit from dependency injection.

3

What is the purpose of the @Component annotation?

Answer

The @Component annotation marks a class as a Spring bean to be automatically detected during component scanning enabled by @ComponentScan. Spring creates an instance of this class and places it in the IoC container with a default name (class in camelCase). It's the generic stereotype annotation from which @Service, @Repository and @Controller derive to bring specific business semantics.

4

What are the three types of dependency injection in Spring?

5

How does the @Autowired annotation work?

+19 interview questions

Master Spring Boot for your next interview

Access all questions, flashcards, technical tests, code review exercises and interview simulators.

Start for free