REST API project developed in Java using Spring Boot 3 and MongoDB.
- HandlerInterceptor: Intercepts requests to verify whether they contain the required HTTP header attribute.
- HandlerMethodArgumentResolver: Retrieves a header value and assigns it to an argument type in controller methods.
- AbstractMongoEventListener: Persists historical data for each POST, UPDATE, PATCH, and DELETE operation.
- AuditorAware: Inserts values for auditable attributes such as
username
, documentversion
, anddate
of operations in the persisted document. - Converter and ConverterFactory: Customize data transformations, such as converting enums to
String
orObject
, and formattingLocalDate
toDate
(UTC, no offset) for MongoDB persistence and retrieval. - ConstraintValidator: Validates request fields and associated business rules by declaring an annotation in the request class.
- Asynchronous Task Execution: Uses
CompletableFuture
to handle tasks asynchronously, optimizing performance by managing threads and enabling non-blocking operations. - Logging: Tracks application logs using
Log4j2
. - Global Exception Handler: Manages errors across the application.
- RestTemplate: Facilitates HTTP requests to REST APIs.
- SSL/TLS: Configures secure connections to MongoDB.
- Unit Tests: Comprehensive test coverage for the entire application.
- Java 17
- Spring Boot 3.x.x
- Apache Maven 3.8.6
- spring-common-parent: Manages the Spring Boot version and provide common configurations for plugins and formatting.
- spring-common-lib: Provides shared utilities and features, including:
- Logging: Log4j2 with ECS (Elastic Common Schema) layout (for non-local environments).
- Http: Pre-configured HTTP client utilities with customizable RestTemplate configurations for efficient connection management, proxy settings, and basic authentication.
- Utils: Utility classes for serialization, object mapping, thread context management in asynchronous operations, and configuring asynchronous task execution with
CompletableFuture
.
- MongoDB Setup: Instructions for MongoDB setup and index creation.
- Git Hooks Setup: Automated Git hooks to enforce code formatting standards with Maven and the Spotless plugin.
- Run the
SpringMongoDBDemoApplication
class as Java Application.
For environments other than local, additional configurations are required:
- Set Environment Variables: Set the following environment variables to configure the application:
DB_HOST
,DB_PORT
,DB_NAME
,DB_USERNAME
,DB_PASSWORD
, andDB_SSL_KEYSTORE_PASSWORD
. - Generate Keystore: Generate a
mongodb-keystore.p12
file and place it in the/resources
directory. This keystore will store the necessary certificates. For detailed steps on generating the required certificates and creating the keystore file, follow the instructions in the Enable SSL/TLS on MongoDB Server.
Follow the AWS Docker guide to deploy a Java App and MongoDB instances and how to set up Nginx as a reverse proxy with a valid Wildcard SSL/TLS certificate.