🚀 A hands-on journey to understand Spring Framework by building it from scratch!
A lightweight, educational implementation of the Spring IOC container that brings the magic of Spring to life. This project demystifies Spring's core mechanisms by implementing dependency injection, AOP proxies, event-driven architecture, type conversion, and a mini MVC framework - all with clean, readable code.
Ever wondered how Spring's "magic" actually works? This project peels back the curtain on:
- How does
@Autowiredknow what to inject? - What's really happening with AOP proxies?
- How does Spring solve circular dependencies?
- What makes the IOC container tick?
Perfect for developers who want to level up their Spring knowledge by understanding the internals!
Dive deep into the implementation details:
- Handwritten Spring XML Injection
- Handwritten Spring Annotation Injection
- Handwritten Spring Simple MVC
- ✅ XML-based bean injection
- ✅ Annotation-based bean injection
- ✅ Basic MVC functionality with route mapping
- ✅ AOP (Aspect-Oriented Programming) support
- ✅ Circular dependency resolution (three-level cache mechanism)
- ✅ Event-driven architecture
- ✅ Type conversion system
- 🔄 Recursive injection
- 📦 Property injection
- 🔗 Reference injection with circular dependency resolution
- 🏷️ Annotation-based configuration:
@Component- Mark classes as Spring beans@Autowired- Automatic dependency injection@Value- Inject values from properties@Qualifier- Specify which bean to inject@Scope- Define bean scope (singleton/prototype)
- 🎭 Singleton and prototype scope switching
This project showcases real-world design patterns in action:
- 🏭 Factory Pattern: Bean creation through
BeanFactoryandApplicationContext - 🎯 Singleton Pattern: Default singleton scope for beans
- 🔌 Adapter Pattern: AOP advice adaptation and MVC controller adaptation
- 🎭 Proxy Pattern: Dynamic proxies using JDK and CGLIB for AOP
- 📋 Template Method Pattern: Abstract classes define skeleton algorithms (
AbstractBeanFactory,AbstractApplicationContext) - 👀 Observer Pattern: Event mechanism with
ApplicationEventandApplicationListener
# Clone the repository
git clone https://github.com/laowenruo/Spring-IOC.git
# Navigate to the project
cd Spring-IOC
# Build with Maven
mvn clean installContributions are what make the open-source community amazing! Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the Apache License 2.0. See LICENSE for more information.
- Inspired by the Spring Framework
- Built for learning and educational purposes
- Special thanks to all contributors!
⭐ If you find this project helpful, please consider giving it a star!