Skip to content

TheComputationalCore/SpringIOC

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

10 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ Spring IOC, Beans & JPA β€” Product Catalog System

Java Spring SpringBoot Thymeleaf JPA H2 Maven Status

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.


πŸ“Œ Table of Contents


πŸ“– Overview

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.


🌟 Features

βœ” Dependency Injection & IoC

Services and controllers are wired automatically using Spring Beans.

βœ” Add Products

Fill out a form and store product data in H2 DB via JPA.

βœ” Display Products

See all products in a table with sorting and clean UI.

βœ” Filter by Category

Uses repository-level custom query.

βœ” Thymeleaf UI

Server-side rendered dynamic HTML pages.

βœ” In-Memory H2 Database

Zero configuration, auto‑created schema.


πŸ› System Architecture

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]
Loading

πŸ”„ Flow Diagram (Page β†’ Controller β†’ Service β†’ DB)

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
Loading

🧰 Tech Stack

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

πŸ“‚ Project Structure

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

πŸ”— Endpoints & Views

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

πŸ—„ Entity Model

Product.java

id       (Long, Auto-generated)
name     (String)
price    (Double)
category (String)

▢️ How to Run

1. Clone the Repo

git clone <REPO_URL>
cd SpringIOC

2. Build the Project

mvn clean install

3. Run

mvn spring-boot:run

4. Access in Browser

http://localhost:8080/

πŸ—ƒ H2 Database Access

Visit:

http://localhost:8080/h2-console

Use:

Key Value
JDBC URL jdbc:h2:mem:productdb;DB_CLOSE_ON_EXIT=FALSE
Username sa
Password (empty)

πŸ›  Troubleshooting

⚠ Whitelabel Error

Caused by template naming mismatch.
Ensure:

return "addproduct";  β†’ templates/addproduct.html
return "displayproduct"; β†’ templates/displayproduct.html

⚠ H2 Shutdown Error

Fixed by:

spring.datasource.url=jdbc:h2:mem:productdb;DB_CLOSE_ON_EXIT=FALSE

πŸ“„ License

MIT License.


Releases

No releases published

Packages

No packages published