Bean Articles
4 articles about Bean. Explore Spring Boot implementation, design, and operations across related topics.
-
Understanding Spring Boot Bean Scopes - When to Use singleton, prototype, request, and session
A thorough explanation of how Spring Boot's five Bean scopes (singleton/prototype/request/session/application) work and when to use each. Covers the pitfall of 'getting the same instance even though @Scope("prototype") was applied,' and introduces four workarounds using ObjectProvider, @Lookup, and jakarta.inject.Provider 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 are @Configuration and @Bean in Spring Boot? Differences from @Component and How to Use Them
Explains the differences between @Configuration and @Bean in Spring Boot, and how to use them alongside @Component with practical examples. Covers Bean registration for external libraries, argument injection in @Bean methods, CGLIB proxy behavior, and how to swap beans in tests, organized with clear decision criteria.