- Author: Andres Solorzano.
- Level: Advanced.
- Technologies: Java, Spring Boot, Spring Native, Spring WebFlux, Quartz, Flyway, Testcontainers, Postgres, DynamoDB and Docker.
This project uses the Spring Boot Framework to handle errors in a Spring Native application that uses WebFlux and i18n. The idea is to use a TDD methodology from the beginning with the support of Testcontainers to execute the Integration Tests. This project also uses Docker with the compose plugin to deploy a local cluster alongside the other required services by the Spring Boot microservice.
This project has been configured to let you generate either a lightweight container or a native executable. It is also possible to run your tests in a native image.
NOTE: GraalVM 22.3+ is required.
First, generate the Spring Native image:
./mvnw clean -Pnative native:compile
Then, execute the following command from the root of the project:
docker compose up --build
Execute the following command:
aws dynamodb scan \
--table-name Devices \
--endpoint-url http://localhost:4566
Use this option if you want to explore more options such as running your tests in a native image.
IMPORTANT: The GraalVM native-image
compiler should be installed and configured on your machine.
Deploy the required services using Docker Compose command:
docker compose up tasks-postgres tasks-localstack
Open a new terminal window and export the following environment variables:
export HIPERIUM_CITY_TASKS_DB_CLUSTER_SECRET='{"dbClusterIdentifier":"hiperium-city-tasks-db-cluster","password":"postgres123","dbname":"HiperiumCityTasksDB","engine":"postgres","port":5432,"host":"localhost","username":"postgres"}'
export AWS_DEFAULT_REGION=ap-southeast-2
export AWS_ACCESS_KEY_ID=DUMMY
export AWS_SECRET_ACCESS_KEY=DUMMY
export AWS_ENDPOINT_OVERRIDE=http://localhost:4566
Then, create and run the native executable from the project's root directory:
$ ./mvnw clean native:compile -Pnative spring-boot:run
You can also run your existing tests suite in a native image. This is an efficient way to validate the compatibility of your application.
To run your existing tests in a native image, run the following goal:
$ ./mvnw test -PnativeTest
For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- GraalVM Native Image Support
- Testcontainers Postgres Module Reference Guide
- Spring Reactive Web
- Spring Data JPA
- Testcontainers
- Quartz Scheduler
- Flyway Migration
The following guides illustrate how to use some features concretely:
These additional references should also help you: