Postgraduate course completion work
This project is a Spring Boot application developed as part of a postgraduate course completion work. It uses Domain-Driven Design (DDD) principles and connects to a MySQL database for production and development environments, with an in-memory H2 database for testing.
The DDD model for this project is documented on Miro:
https://miro.com/app/board/uXjVJezNcEM=/
-
Docker and Docker Compose installed.
-
Java 21 (for local development or testing).
-
Maven (for building the JAR and running tests).
-
A
target/*.jarfile built from the project (e.g.,mvn clean package). -
A
.envfile in the project root with the following variables:# Production DB_URL="jdbc:mysql://mysql:3306/mydatabase" DB_USERNAME="myuser" DB_PASSWORD="secret" # Development DEV_DB_URL="jdbc:mysql://mysql:3306/mydatabase" DEV_DB_USERNAME="myuser" DEV_DB_PASSWORD="secret" # Test TEST_DB_URL="jdbc:h2:mem:testdb" TEST_DB_USERNAME="sa" TEST_DB_PASSWORD=""
-
Ensure
.envis added to.gitignoreto avoid committing sensitive data.
Build the images for the application:
docker-compose buildStart the application with the prod profile (uses application-prod.properties):
docker-compose up --build app- Runs the MySQL database and the application on port
8080. - To run in the background:
docker-compose up -d --build app.
Start the application with the dev profile (uses application-dev.properties):
docker-compose up --build app-dev- Runs the MySQL database and the application on port
8081. - To run in the background:
docker-compose up -d --build app-dev.
Stop and remove containers (preserves MySQL data):
docker-compose downTo also remove the MySQL data volume (resets the database):
docker-compose down -vCheck logs for production:
docker-compose logs -f appCheck logs for development:
docker-compose logs -f app-devRun the application with the dev profile to execute Gatling performance tests:
mvn clean gatling:test -PperformanceRun tests with the test profile (uses application-test.properties with H2 database):
mvn testTo run tests in Docker, use a separate docker-compose-test.yml:
docker-compose -f docker-compose-test.yaml up --buildThe docker-compose.yml defines:
mysql: MySQL 8.0 database withmydatabase(used byprodanddevprofiles).app: Production service on port8080(usesSPRING_PROFILES_ACTIVE=prod).app-dev: Development service on port8081(usesSPRING_PROFILES_ACTIVE=dev).
For a separate development database (devdb), create a docker-compose-dev.yml (see project documentation or contact the maintainer).
-
Ensure ports
8080,8081, and3306are free on your host. -
In production, remove the
3306:3306port mapping frommysqlindocker-compose.ymlfor security. -
The
testprofile uses an in-memory H2 database and does not require the MySQL service. -
For debugging, access the MySQL container:
docker exec -it hackaton-database mysql -u myuser -psecret mydatabase