Dependency Injection Articles
Articles covering the fundamentals of dependency injection and bean design as the foundation for understanding Spring Boot.
-
How to Reduce Boilerplate Code with Lombok in Spring Boot
A practical explanation of the roles and proper usage of Lombok annotations frequently used in Spring Boot development (@Data, @Builder, @RequiredArgsConstructor, @Slf4j, etc.). Also covers pitfalls when used with JPA Entity and how to combine it with constructor injection.
-
Understanding Spring Boot Bean Scopes - When to Use singleton, prototype, request, and session
Explains the behavior and proper use of Spring Boot's five Bean scopes (singleton/prototype/request/session/application). Also covers the pitfalls of injecting prototype beans into singletons and how to resolve them using ObjectProvider and @Lookup, with implementation examples.
-
Understanding Spring Boot Bean Lifecycle - How to Use @PostConstruct, @PreDestroy, and InitializingBean
A visual walkthrough of the Spring Bean lifecycle from creation through initialization to destruction, explaining how to choose between four implementation patterns — @PostConstruct, @PreDestroy, InitializingBean, and DisposableBean — based on your use case.
-
Spring @Bean "Name" Guide - When to Set It? How Does It Work? What's the Priority?
A practical guide to the role of the 'name' attribute on Spring Boot's @Bean. Covers default naming conventions (method name = Bean name), how to assign explicit names/aliases, the priority of @Qualifier, @Primary, and parameter names, avoiding Bean name collisions, and tips for using constants, all with code examples.
-
What is @Component in Spring Boot? Differences from @Bean and How to Use It
A beginner-friendly explanation of what @Component is in Spring Boot. Covers the differences from @Bean, criteria for choosing between them, the relationship with @Service/@Repository, and practical usage including constructor injection with code examples.
-
Spring Boot Dependency Injection Explained with Examples
Learn how Dependency Injection (DI) works in Spring Boot. Covers constructor injection, @Autowired, and the benefits of DI for testable, maintainable code — with practical examples.