← Spring Boot learning path
Spring Boot · Module 2 of 10

Dependency injection and beans

Let Spring create and wire objects for you.

📖 Key ideas

  1. Spring manages objects called beans in the ApplicationContext.
  2. Stereotypes: @Component, @Service, @Repository, @Controller.
  3. Constructor injection is preferred over field injection.
  4. @Configuration classes with @Bean methods define beans manually.
  5. Default scope is singleton (one instance).
💡 Real-life example: The Spring container is a staffing agency: you list the roles you need and it sends ready workers.
BeanObject managed by Spring
@ServiceMarks business logic class
Constructor injectionDependencies passed via constructor
Singleton scopeOne shared instance