Spring Boot Blog REST API
repository·main·Indexed 18 days ago
https://github.com/rameshmf/springboot-blog-rest-apiA reference implementation of a Blog REST API using Spring Boot 3.2.1 and Spring Security 6+. Features include JWT 0.12.3 for stateless authentication, Spring Data JPA with MySQL, CRUD operations with pagination and sorting, DTO patterns, and Docker containerization for AWS deployment.
What's inside springboot-blog-rest-api
- This project is the source code for a complete Blog Application built using Spring Boot. It serves as a reference implementation for building real-time REST APIs. The project is specifically upgraded to use Spring Boot 3.2.1 and JWT 0.12.3, ensuring compatibility with modern Spring Security 6+ standards.
Core Technologies and Learning Objectives
mainThe project demonstrates the integration of several key technologies for building production-ready RESTful services:
- Frameworks: Spring Boot 3+, Spring Security 6+
- Security: JSON Web Token (JWT) for stateless authentication and role-based authorization (both In-memory and DB-based).
- Data Access: Spring Data JPA (Hibernate) with MySQL database, including one-to-many and many-to-many mappings.
- API Design: Implementation of CRUD operations, Pagination, Sorting, URI versioning strategies, and DTO (Data Transfer Object) patterns.
- Validation & Error Handling: Spring Boot REST API validation and centralized exception handling.
- DevOps & Deployment: Docker containerization and deployment to AWS Cloud.
Build the project with Maven
mainTo build the project, navigate to the root directory of the project and execute the build command. You can use a local Maven installation or the included Maven Wrapper (
mvnw).# If Maven is installed on your machine mvn clean package # If Maven is NOT installed (using the wrapper) ./mvnw clean packageSet up the MySQL database
mainBefore running the application, you must manually create a MySQL database named
myblog. Hibernate will automatically create the necessary tables once the application starts, but the database container must exist.create database myblogRun the Spring Boot application
mainOnce the database is created and the project is built, use the following command to start the application. Hibernate will handle the automatic creation of database tables based on the entity mappings.
mvn spring-boot:runInitialize roles in the database
mainAfter the application has started and tables are created, you must manually insert the required roles into the
rolestable to ensure proper authorization works. Use the following SQL statement:INSERT INTO `myblog.roles` VALUES (1,'ROLE_ADMIN'),(2,'ROLE_USER');