A simple Spring Core (IoC + Dependency Injection) based Java application that demonstrates how to manage objects like Customer, Product, and Order using annotations and configuration classes.
This project showcases:
- Spring Annotation-based configuration
- Component Scanning
- Setter-based Dependency Injection
- Loose coupling using Spring IoC container
The application creates and links:
- A
Customer - A
Product - An
Order(which depends on both)
com.nit
│
├── config
│ └── AppConfig.java
│
├── sbeans
│ ├── Customer.java
│ ├── Product.java
│ └── Order.java
│
└── main
└── TestOrder.java
- Java
- Spring Core (Annotations)
- Eclipse / Any Java IDE
-
Spring container is initialized using
AnnotationConfigApplicationContext -
Components are auto-detected using
@ComponentScan -
Beans are created:
- Customer
- Product
- Order
-
Dependencies are injected using
@Autowired -
Order object prints all details
- Defines component scanning
- Starts Spring container
- Retrieves beans and sets values
- Holds customer details
- Holds product information
- Injects Customer & Product using Spring
Order [orderId=101,
customer=Customer [name=Pawan, email=pawan@gmail.com],
product=Product [productName=Laptop, price=70000.0]]
- IoC Container
- Dependency Injection (Setter Injection)
- Annotation-based configuration
- Bean lifecycle basics
- Import project into IDE
- Add Spring Core dependencies (if not already added)
- Run:
TestOrder.java
- Add constructor injection
- Add XML configuration version
- Convert into Spring Boot project
- Add REST API layer
Your Name
Give it a star ⭐ and feel free to fork it!