AL
alvelchev/spring-practices-demo
Welcome to the Spring Practices Demo – a powerful Spring Boot application designed to support data JPA, pageable, and sorting with an intuitive Swagger interface. Explore and learn best practices in Java development, including efficient techniques with MapStruct, seamless database migration using Flyway, and more.
Please ⭐ this repository if you find it useful. Thank you.
Spring Practices Demo
Table of Contents
- Introduction
- Key Features
- GitHub Actions Pipelines Integration
- How to Start the Project
- Provided Examples with Implementation on Spring Boot
- Branches
- Git Commit Plugin Response
Introduction
Welcome to the Spring Boot Best Practices Application! This project serves as a comprehensive demonstration of
fundamental Java Spring concepts, highlighting industry best practices and essential techniques for building robust
Spring Boot applications. The project is designed to be a reference for developers of all levels, providing examples of
a wide range of Spring Boot features and implementations.
Key Features and Demonstrations
- Model-View-Controller (MVC) Architecture: Embracing the MVC pattern for a well-organized and modular structure.
- MapStruct for Object Mapping: Streamlining object mapping for enhanced readability and maintainability.
- Flyway for Database Migration: Seamless database migration management through Flyway.
- JUnit 5 Configuration: Configured JUnit 5 for effective testing and robust code coverage.
- JSON Data Processing: Efficiently reading and filtering data from JSON files.
- Basic CRUD Operations: Implementation of essential CRUD operations for effective resource management.
- Pageable Response Handling: Demonstrating easy filtering, sorting, and more with Pageable responses.
- Global Exception Handling: A global exception handler for managing exceptions across the codebase.
- Custom Spring Validator: Examples of custom Spring validators at field and class levels.
- CriteriaBuilder for Data Retrieval: Using CriteriaBuilder for advanced data retrieval.
- Spring Boot Actuator: Configuring Spring Boot Actuator for collecting application metrics.
- Git Information Injection: Injecting Git information into Spring for version tracking.
- Quartz Scheduler: Implementation of Quartz scheduler using Cron Triggers and Expressions.
- Spring Custom Events: Leveraging Spring Custom Events for event-driven architecture.
GitHub Actions Pipelines Integration
- Integrated with GitHub Actions for code analyses with SonarCloud and Codecov for code coverage reports.
- Integrated with Docker. On every push event to the main branch, a new Docker image is generated.
- Integrated with Maven Dependency tree generation.
SonarCloud:
Codecov:
- Codecov Example (example of how to set up Codecov badge)
- Codecov Dashboard
How to Start the Project
- Clone the repository.
- Start the local PostgreSQL.
- Run Maven clean install.
- Open the Swagger URL to test the endpoints: Swagger UI
- Open Spring Boot Actuator endpoint: Actuator
Provided Examples with Implementation on Spring Boot
- Pageable and Sorting Response: Baeldung Tutorial → (
controller package) - Flyway: Baeldung Tutorial → (resources.db.migration
package) - JUNIT5: Baeldung Tutorial → (tests package)
- Global Exception Handler in Java: Baeldung Tutorial → (
advice package) - CriteriaBuilder: Baeldung Tutorial → (repository.custom
package and CriteriaBuilderExampleController) - Custom Validator: Baeldung Tutorial → (validator package)
- Spring Boot Actuator: Baeldung Tutorial
- Injecting Git Information Into Spring: Baeldung Tutorial → (
HistoryLinkProvidingGitInfoContributor.class) - Quartz Job Scheduler with Cron Triggers and Expressions: Quartz Scheduler → (
configuration.quartz package) - Spring Custom Events: Baeldung Tutorial → (event package)
Branches:
- Branch with name: "java11Version" is set up for JDK11
- Main branch is with the newest spring boot 3.0.2 and JDK17
Git commit plugin response:
// 20221101225521
// http://localhost:8099/actuator/info
{
"git": {
"commit": {
"message": {
"short": "Merge branch 'main' into gitCommitPlugin"
},
"id": {
"abbrev": "34078b6",
"full": "34078b613c32ac9cf4f076b42232e3d9523aaeb7",
"describe": "34078b6-dirty"
},
"time": "2022-11-01T18:59:21Z",
"history": "https://github.com/alvelchev/spring-practices-demo/commit/4b36876"
},
"branch": "gitCommitPlugin",
"build": {
"time": "2022-11-01T20:53:58Z",
"version": "0.0.1"
}
},
"build": {
"artifact": "springpageable",
"name": "springpageable",
"time": "2022-11-01T20:53:56.838Z",
"version": "0.0.1",
"group": "com.springpracticesdemo"
}
}