A ready-to-use Spring Boot boilerplate project that helps you get started fast with best practices like:
- ✅ JWT-based Authentication
- 🔐 Role-based Authorization Middleware
- 🧠 Custom Validation (Exists & Unique)
- 🧾 Clean Response Formatting
- 🚨 Global Exception Handling
Why write the same setup code again and again, when you can just fork this and start building? 😎
📍 GitHub: https://github.com/PrasGi/init-project-springboot
- Java 21
- Spring Boot
- JPA (Hibernate)
- Lombok
- Slf4j
- JWT
- Custom Middleware
- Global Exception Handler
- 🧾 Clean Response Helper: Consistent response format for both success and error.
- 🔒 JWT Authentication: Stateless login with token generation and validation.
- 🧠 Custom Validation Annotations:
@ExistsInDatabase: Check if a value exists in DB.@UniqueValue: Check if a value is unique in DB.
- 🛡️ Middleware Support: Use annotations to protect routes based on auth/roles.
⚠️ Global Exception Handling: Beautiful error responses, even for validation errors.
git clone https://github.com/PrasGi/init-project-springboot.git
cd init-project-springbootEdit application.properties or application.yml:
spring.datasource.url=jdbc:mysql://localhost:3306/your_db
spring.datasource.username=root
spring.datasource.password=your_password./mvnw spring-boot:runOr use your favorite IDE (IntelliJ, Eclipse, etc).
POST /login
{
"email": "user@example.com",
"password": "secret123"
}{
"status": true,
"statusCode": 200,
"message": "Login berhasil",
"data": "JWT_TOKEN_HERE"
}To secure endpoints using JWT and roles, use this annotation:
@UseMiddleware(names = { "auth", "roles:user" })@ExistsInDatabase(entity = User.class, field = "email", message = "Email not found")
private String email;@UniqueValue(entity = User.class, field = "email", message = "Email already taken")
private String email;Handles validation errors and returns consistent error structure:
{
"status": false,
"statusCode": 400,
"message": "Failed validation",
"errors": {
"email": "Email already taken"
}
}Feel free to fork, clone, and send PRs.
Let’s make backend development faster and cleaner for everyone!
Made with ☕ & ❤️ by @PrasGi
MIT License – use it, modify it, share it!