Skip to main content
This quickstart guide will help you clone, configure, and run the DriveX Backend API locally. You’ll make your first API call in under 5 minutes.

Prerequisites

Before you begin, ensure you have the following installed:
  • Java 17 or higher (Download OpenJDK)
  • Maven 3.9+ (Download Maven)
  • MySQL database server running locally or accessible remotely
  • Git for cloning the repository
If you prefer using Docker, skip to the Docker Setup section for a containerized deployment.

Quick Setup

1

Clone the Repository

Clone the DriveX Backend repository from GitHub:
git clone https://github.com/rofaba/drivex-backend.git
cd drivex-backend
2

Configure Database Connection

Create or edit the src/main/resources/application.properties file with your MySQL credentials:
spring.application.name=DriveX-backend

# MySQL Database Configuration
spring.datasource.url=jdbc:mysql://localhost:3306/drivex
spring.datasource.username=your_username
spring.datasource.password=your_password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

# JPA/Hibernate Configuration
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

# Server Configuration
server.servlet.context-path=/api
server.port=8080
server.address=0.0.0.0
Make sure your MySQL database drivex exists before starting the application. Create it with:
CREATE DATABASE drivex CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
3

Install Dependencies

Use Maven to download all required dependencies:
mvn clean install
This command will:
  • Clean any previous build artifacts
  • Download all dependencies defined in pom.xml
  • Compile the project
  • Run tests (if any)
  • Package the application
4

Run the Application

Start the Spring Boot application using Maven:
mvn spring-boot:run
Or run the JAR file directly:
java -jar target/DriveX-0.0.1-SNAPSHOT.jar
You should see output indicating the server is running:
Started DriveXBackendApplication in 3.456 seconds (JVM running for 4.123)
5

Verify the API is Running

Test the API with a simple GET request to list all vehicles:
curl http://localhost:8080/api/vehicles
You should receive a JSON response (empty array if no vehicles exist yet):
[]
6

Make Your First API Call

Create a new vehicle using a POST request:
curl -X POST http://localhost:8080/api/vehicles \
  -H "Content-Type: application/json" \
  -d '{
    "brand": "BMW",
    "model": "X5",
    "year": 2024,
    "vehicleType": "SUV",
    "pricePerDay": 150.00,
    "available": true
  }'
The API will respond with the created vehicle including its auto-generated ID and reference:
{
  "id": 1,
  "brand": "BMW",
  "model": "X5",
  "year": 2024,
  "reference": "BMW2024A1B2",
  "vehicleType": "SUV",
  "pricePerDay": 150.00,
  "available": true
}

Docker Setup

For a containerized deployment, use the included Dockerfile:
1

Build the Docker Image

Build the multi-stage Docker image:
docker build -t drivex-backend .
This uses the production-ready Dockerfile that:
  • Builds the JAR using Maven in stage 1
  • Creates a lightweight runtime image with Eclipse Temurin JDK 17
2

Run the Container

Run the container with environment variables:
docker run -d \
  -p 8080:8080 \
  -e SPRING_DATASOURCE_URL=jdbc:mysql://host.docker.internal:3306/drivex \
  -e SPRING_DATASOURCE_USERNAME=your_username \
  -e SPRING_DATASOURCE_PASSWORD=your_password \
  --name drivex-api \
  drivex-backend
Use host.docker.internal to connect to MySQL running on your host machine from within the container.
3

Verify Container is Running

Check the container logs:
docker logs -f drivex-api
Test the API:
curl http://localhost:8080/api/vehicles

Development Mode

For active development with hot reload, the project includes Spring Boot DevTools:
# Run in development mode with auto-restart
mvn spring-boot:run
DevTools automatically restarts the application when you modify:
  • Java classes
  • Property files
  • Static resources
DevTools is only active when running the application from the classpath (via mvn spring-boot:run), not when running a packaged JAR.

Testing the API

Here are some common API endpoints to test:
curl http://localhost:8080/api/vehicles

Next Steps

Installation Guide

Detailed setup for production environments

API Reference

Complete API endpoint documentation

Troubleshooting

Change the port in application.properties:
server.port=8081
Or set the PORT environment variable:
PORT=8081 mvn spring-boot:run
Verify:
  1. MySQL server is running: mysql -u root -p
  2. Database exists: SHOW DATABASES;
  3. User has permissions: GRANT ALL PRIVILEGES ON drivex.* TO 'your_username'@'localhost';
  4. Connection URL is correct in application.properties
Clear Maven cache and rebuild:
mvn clean install -U
Ensure Java 17 is installed:
java -version
Remember that all endpoints are prefixed with /api due to the context path configuration. Use:
http://localhost:8080/api/vehicles
Not:
http://localhost:8080/vehicles

Build docs developers (and LLMs) love