Spring Framework Beans are the building blocks of Spring applications. Here's a quick breakdown:
📌 What are Beans?
- Definition: A Bean is a Java object managed by the Spring IoC container.
- Key Features:
- Managed by Spring's DI (Dependency Injection) system
- Configured via XML, annotations, or Java code
- Can be singleton, prototype, or scoped (e.g., request, session)
🧠 Bean Lifecycle Stages
- Instantiation 📦
Spring creates the bean instance using the constructor. - Population of Properties 🔁
Dependencies are injected via setters or constructors. - Aware Interfaces 🎯
Beans can access Spring infrastructure (e.g.,ApplicationContextAware
). - BeanPostProcessor 🛠
Custom logic can be applied before/after initialization. - Initialization ✅
Methods like@PostConstruct
orinit-method
are called. - Usage 🚀
The bean is ready for application use. - ** Destruction ** ❌
@PreDestroy
ordestroy-method
is invoked when the container shuts down.
📚 Recommended Reading
For visual learners, check out our Spring Boot Video Series to see Beans in action! 🎥