This project demonstrates core Spring Framework (Spring Core / IoC) concepts such as Annotation-based configuration, Dependency Injection, and Bean Scopes (singleton vs prototype).
This is a simple Java application that simulates an order delivery system where:
- A
Customerplaces an order - A
DeliveryServiceprocesses and delivers the order
The main goal is to understand how Spring manages object creation and dependency injection using annotations.
-
✅ Annotation-based configuration (
@Configuration,@ComponentScan) -
✅ Dependency Injection using
@Autowired -
✅ Bean Scopes:
- Singleton (default scope)
- Prototype
-
✅ Spring IoC Container usage
com.nit
│
├── config
│ └── AppConfig.java
│
├── main
│ └── TestApp.java
│
└── sbeans
├── Customer.java
└── DeliveryService.java
Spring configuration is done using Java annotations:
@Configuration
@ComponentScan(basePackages = "com.nit.sbeans")
public class AppConfig {
}This tells Spring to scan the specified package for components.
The Customer class depends on DeliveryService, which is injected automatically:
@Autowired
private DeliveryService deliveryService;@Scope("prototype")- A new object is created every time the bean is requested from the container.
- Only one shared object exists throughout the application.
- Spring container is initialized using
AnnotationConfigApplicationContext - Two
DeliveryServicebeans are requested → SAME instance - Two
Customerbeans are requested → DIFFERENT instances - Each customer places an order
- Output confirms scope behavior using hashcodes
- Java 8 or higher
- IDE (Eclipse / IntelliJ / VS Code)
- Clone the repository
- Open in your IDE
- Run
TestApp.java
OR via terminal:
javac *.java
java com.nit.main.TestApp
====Sevice Details===
Order is placing...
Service Name: Swiggy Delivery
Total no of orders : 2
Order is Delivered
-----Customer Detail----
Customer ID: CUS101
Customer Name: Raj
====Sevice Details===
Order is placing...
Service Name: Swiggy Delivery
Total no of orders : 2
Order is Delivered
-----Customer Detail----
Customer ID: CUS103
Customer Name: Rahul
Hash code of customer1: 12345678
Hash code of customer2: 87654321
- ✔
Customerbeans have different hashcodes → Prototype scope works - ✔
DeliveryServicebehaves like a shared object → Singleton scope - ✔ Even multiple calls to
getBean()return the sameDeliveryServiceinstance
By completing this project, you will understand:
- How Spring IoC container manages beans
- Difference between Singleton and Prototype scope
- Real-world usage of Dependency Injection
- Annotation-based configuration in Spring
- Java
- Spring Core (IoC Container)
- Annotation-based configuration
This project is created for learning and practicing Spring Core fundamentals.
⭐ Feel free to fork, modify, and experiment with this project!