A mock travel booking REST API built with Spring Boot, Spring Data JPA, Spring Security, MySQL, and Flyway.
- Java 21
- Spring Boot 4
- Spring Data JPA / Hibernate
- Spring Security / JWT
- MySQL
- Flyway
- MapStruct
- Maven
- Swagger / OpenAPI
- Thymeleaf
Install:
- Java 21
- MySQL
- Git
Check Java version:
java -versionThe project includes Maven Wrapper, so Maven does not need to be installed globally.
Create a MySQL database:
CREATE DATABASE trip_go;Flyway will automatically create/update the database schema when the application starts.
The application requires database credentials and a JWT secret.
Create a .env file in the project root:
DB_USERNAME=root
DB_PASSWORD=your_password
JWT_SECRET=tripgo-local-secret-key-at-least-32-bytesMake sure .env is ignored by Git:
.envThe application configuration should reference these variables:
spring.datasource.url=jdbc:mysql://localhost:3306/trip_go
spring.datasource.username=${DB_USERNAME}
spring.datasource.password=${DB_PASSWORD}
spring.jpa.hibernate.ddl-auto=validate
spring.flyway.enabled=true
app.jwt.secret=${JWT_SECRET}
app.jwt.expiration=PT1HSpring Boot does not automatically load
.env.
On macOS/Linux, load the environment variables before running:
set -a
source .env
set +aAlternatively, configure DB_USERNAME, DB_PASSWORD, and JWT_SECRET in your IDE Run Configuration.
./mvnw spring-boot:runmvnw.cmd spring-boot:runThe application will start at:
http://localhost:8080
Flyway migrations are located at:
src/main/resources/db/migration/
They are executed automatically when the application starts.
The startup flow is:
Start Application
↓
Flyway Migration
↓
Hibernate Schema Validation
↓
Application Ready
After starting the application, open Swagger UI:
http://localhost:8080/swagger-ui.html
OpenAPI JSON:
http://localhost:8080/v3/api-docs
For protected APIs:
- Call
/api/v1/auth/login - Copy the returned JWT
- Click Authorize in Swagger UI
- Enter the JWT
- Call protected endpoints
Run tests and build:
./mvnw clean verifyCreate the JAR:
./mvnw clean packageRun the packaged application:
java -jar target/tripgo-api-0.0.1-SNAPSHOT.jar- Do not commit
.env, database passwords, or JWT secrets. - Database schema changes should be made through Flyway migrations.
- Hibernate is configured with
ddl-auto=validate, notcreateorupdate. - This project is intended for learning and demonstration purposes.