A simple Spring Core (Annotation-based) project demonstrating Dependency Injection (DI) and Component Scanning using a Hospital Management scenario.
This project simulates a basic hospital system where:
- A Doctor treats a Patient
- Both are managed inside a Hospital
- Dependencies are injected using Spring Framework (Core)
It’s a beginner-friendly project to understand:
- Spring IoC Container
- Dependency Injection (Setter Injection)
- Component Scanning
- Annotation-based configuration
- Java
- Spring Core Framework
- Eclipse IDE (or any Java IDE)
com.nit
│
├── config
│ └── AppConfig.java
│
├── main
│ └── TestHospitalManagement.java
│
└── sbeans
├── Doctor.java
├── Patient.java
└── Hospital.java
- Enables component scanning for Spring Beans
- Uses
@Configurationand@ComponentScan
👉 Source:
-
Contains:
- name
- specialization
-
Marked as
@Component("doc")
👉 Source:
-
Contains:
- name
- disease
-
Marked as
@Component("pat")
👉 Source:
-
Contains:
- hospital name
- Doctor (Autowired)
- Patient (Autowired)
-
Uses Setter Injection with
@Autowired
👉 Source:
- Loads Spring Container using
AnnotationConfigApplicationContext - Retrieves beans
- Sets values dynamically
- Prints hospital details
👉 Source:
- Clone the repository
- Open in Eclipse / IntelliJ
- Add Spring Core dependencies (if not already added)
- Run:
TestHospitalManagement.java
Hospital =City Hospital
Doctor=Dr. Sharma (Cardiologist)
Patient= Amit Disease=(Heart Problem)
- ✔️ Spring IoC Container
- ✔️ Dependency Injection (Setter-based)
- ✔️ Annotation Configuration
- ✔️ Component Scanning
- ✔️ Loose Coupling
This project is ideal for:
- Beginners learning Spring Framework
- Understanding how beans are managed
- Practicing real-world object relationships
- Add Constructor Injection
- Introduce Interfaces (for better abstraction)
- Add Spring Boot version
- Connect to database (JDBC / JPA)
Feel free to fork this repo and improve it!
This project is for educational purposes.
⭐ If you found this helpful, consider giving it a star!