A complete, productionβstyle demonstration of Spring IOC, Beans, Dependency Injection, Spring MVC, Spring Data JPA, and Thymeleaf, wrapped into a functional Product Catalog Web Application.
This project showcases realβworld Spring Framework fundamentals with a clean architecture and fully working CRUD features.
- Overview
- Features
- System Architecture
- Flow Diagram
- Tech Stack
- Project Structure
- Endpoints & Views
- Entity Model
- How to Run
- H2 Database Access
- Troubleshooting
- License
This Spring Boot + IOC + Beans powered application provides a simple yet powerful Product Catalog with full CRUD behavior through:
- Thymeleafβbased UI
- Spring MVC controllers
- JPA repositories
- H2 in-memory DB
- IOC + DI-managed services
It is ideal for learning or demonstrating Spring Core concepts.
Services and controllers are wired automatically using Spring Beans.
Fill out a form and store product data in H2 DB via JPA.
See all products in a table with sorting and clean UI.
Uses repository-level custom query.
Server-side rendered dynamic HTML pages.
Zero configuration, autoβcreated schema.
graph TD
A[User Browser] --> B[Spring MVC Controller]
B --> C[Service Layer]
C --> D[Repository Layer]
D --> E[(H2 Database)]
B --> F[Thymeleaf Templates]
sequenceDiagram
participant U as User
participant C as Controller
participant S as Service
participant R as JPA Repository
participant DB as H2 DB
U->>C: GET /
C->>U: index.html
U->>C: GET /add-product
C->>U: addproduct.html
U->>C: POST /add-product
C->>S: saveProduct(product)
S->>R: save(product)
R->>DB: INSERT
C->>U: redirect:/
U->>C: GET /display-products?category=...
C->>S: getProducts(...)
S->>R: findByCategory() OR findAll()
R->>DB: SELECT
C->>U: displayproduct.html
| Component | Technology |
|---|---|
| Language | Java 17 |
| Framework | Spring Boot, Spring Core |
| DI / IoC | Spring Beans |
| Persistence | Spring Data JPA (Hibernate) |
| Database | H2 InβMemory |
| Template Engine | Thymeleaf |
| Build Tool | Maven |
src/
βββ main/
β βββ java/com/SpringIOC/demo/
β β βββ controller/
β β β βββ ProductController.java
β β βββ service/
β β β βββ ProductService.java
β β βββ repository/
β β β βββ ProductRepository.java
β β βββ entity/
β β β βββ Product.java
β β βββ SpringIoc1Application.java
β β
β βββ resources/
β βββ templates/
β β βββ index.html
β β βββ addproduct.html
β β βββ displayproduct.html
β βββ application.properties
β βββ static/
β
βββ test/
βββ SpringIoc1ApplicationTests.java
| URL | Method | Description | View |
|---|---|---|---|
/ |
GET | Homepage | index |
/add-product |
GET | Show product form | addproduct |
/add-product |
POST | Save new product | redirect:/ |
/display-products |
GET | Display all or filtered | displayproduct |
id (Long, Auto-generated)
name (String)
price (Double)
category (String)
git clone <REPO_URL>
cd SpringIOCmvn clean installmvn spring-boot:runhttp://localhost:8080/
Visit:
http://localhost:8080/h2-console
Use:
| Key | Value |
|---|---|
| JDBC URL | jdbc:h2:mem:productdb;DB_CLOSE_ON_EXIT=FALSE |
| Username | sa |
| Password | (empty) |
Caused by template naming mismatch.
Ensure:
return "addproduct"; β templates/addproduct.html
return "displayproduct"; β templates/displayproduct.html
Fixed by:
spring.datasource.url=jdbc:h2:mem:productdb;DB_CLOSE_ON_EXIT=FALSE
MIT License.