← Spring Boot learning pathSpring Boot · Module 2 of 10
Dependency injection and beans
Let Spring create and wire objects for you.
📖 Key ideas
- Spring manages objects called beans in the ApplicationContext.
- Stereotypes: @Component, @Service, @Repository, @Controller.
- Constructor injection is preferred over field injection.
- @Configuration classes with @Bean methods define beans manually.
- 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