A lightweight Spring Boot blogging application that demonstrates a full CRUD (Create, Read, Update, Delete) flow for articles. This project uses Spring Data JPA, Thymeleaf templates, and UUID primary keys stored as BINARY(16).
This is a learning project showcasing best practices in Spring Boot development.
🚀 Live Link: BlogSpace
- Java 25 (LTS)
- Spring Boot 4.0.1 (Web, Thymeleaf, Data JPA, Validation)
- Maven (Build tool)
- MySQL 8.0 (JDBC-compatible database)
- Thymeleaf (Server-side HTML templates)
- Docker & Docker Compose (Containerization)
- Complete CRUD Operations: Create, read, update, and delete articles through an intuitive web interface.
- UUID Primary Keys: Uses Java
UUIDwith Hibernate'sGenerationType.UUIDstrategy, optimized asBINARY(16)storage for database performance. - Input Validation: Client-side and server-side validation using Jakarta validation annotations (
@NotBlank,@Size). - Automatic Timestamps: Tracks article creation and modification times with
@CreationTimestampand@UpdateTimestamp. - Server-Side Rendering: Built with Spring MVC and Thymeleaf templates for dynamic HTML generation.
- Exception Handling: Global exception handler for graceful error management and user feedback.
- Profile-Based Configuration: Separate environment configurations for development and production.
- Production Keep-Alive Service: Scheduled pinging mechanism to keep the app alive on free hosting platforms (production profile only).
src/
├── main/
│ ├── java/
│ │ └── com/blog/project/
│ │ ├── BloggingProjectApplication.java (Application entry point)
│ │ ├── controller/
│ │ │ └── BlogController.java (Spring MVC controller for web requests)
│ │ ├── model/
│ │ │ └── Article.java (JPA entity with UUID ID and timestamps)
│ │ ├── repository/
│ │ │ └── BlogRepository.java (Spring Data JPA repository)
│ │ ├── service/
│ │ │ └── KeepAliveService.java (Scheduled task for production)
│ │ └── exception/
│ │ ├── ArticleNotFoundException.java (Custom exception)
│ │ └── GlobalExceptionHandler.java (Centralized error handling)
│ │
│ └── resources/
│ ├── application.properties (Main configuration)
│ ├── application-dev.properties (Development overrides)
│ ├── application-prod.properties (Production overrides)
│ ├── static/
│ │ └── validation.js (Client-side validation scripts)
│ └── templates/ (Thymeleaf templates)
│ ├── index.html (Article list view)
│ ├── add.html (Create article form)
│ ├── update.html (Edit article form)
│ ├── fragments/
│ │ ├── fragment.html (Reusable UI components)
│ │ └── layout.html (Base layout template)
│ └── error/
│ └── error-message.html (Error page template)
└── test/
└── java/
└── com/blog/project/
└── BloggingProjectApplicationTests.java
If you have Docker installed, you can spin up the Application and Database instantly.
docker-compose up --buildThe app will be available at http://localhost:8080.
⚙️ Configuration
The application uses environment variables for database credentials and profile-specific configuration.
-
Set Environment Variables
Create a
.envfile in the project root or set these environment variables in your system:
SPRING_PROFILES_ACTIVE=dev
DB_URL=jdbc:mysql://localhost:3306/blogdb?useSSL=false&serverTimezone=UTC
DB_USER=root
DB_PASS=your_secret_password- Database Schema
This project does not automatically create the schema by default (as
spring.jpa.hibernate.ddl-autois set tonone). You must create thearticlestable in your database first.
CREATE DATABASE blogdb;
CREATE TABLE articles (
id BINARY(16) NOT NULL PRIMARY KEY,
title VARCHAR(255) NOT NULL,
content TEXT NOT NULL,
author VARCHAR(100) NOT NULL,
created_at TIMESTAMP,
updated_at TIMESTAMP
);Note: If you want Hibernate to automatically create or update the schema for you (e.g., during development), you can change the
spring.jpa.hibernate.ddl-autoproperty inapplication-dev.propertiestoupdate.
From the project root, build the application using the Maven wrapper.
On Windows (cmd.exe):
mvnw.cmd clean packageOn macOS / Linux:
./mvnw clean packageRun with the Spring Boot plugin (development):
On Windows (cmd.exe):
mvnw.cmd spring-boot:runOn macOS / Linux:
./mvnw spring-boot:runOr run the compiled jar after building:
java -jar target/project-0.0.1-SNAPSHOT.jarThe application will be available at http://localhost:8080 (unless you changed the port in application.properties).
Run tests with the wrapper:
mvnw.cmd testOr on macOS / Linux:
./mvnw testDeveloped and Maintained by Pranjal Singh