WL
Java Full Stack Developer
Wassim Lagnaoui

Tutorial 01: Project setup

Spring Boot + PostgreSQL setup for the Restaurant App series.

← Back to Tutorials

Project Bootstrapping: Spring Boot + PostgreSQL

This short guide helps you bootstrap the application: pick the right Spring dependencies, set up PostgreSQL, and configure application.yml so the app connects to the database successfully.


Step 1 — Generate a Spring Boot project

Use Spring Initializr (start.spring.io) with:

Download and unzip, or import directly into your IDE.

If you need to add dependencies manually

Ensure your pom.xml includes the following (only the relevant parts shown):

<dependencies>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-jpa</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-validation</artifactId>
  </dependency>
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-security</artifactId>
  </dependency>
  <dependency>
    <groupId>org.postgresql</groupId>
    <artifactId>postgresql</artifactId>
    <scope>runtime</scope>
  </dependency>
  <dependency>
    <groupId>org.projectlombok</groupId>
    <artifactId>lombok</artifactId>
    <optional>true</optional>
  </dependency>
  <!-- Optional, useful in development -->
  <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-devtools</artifactId>
    <scope>runtime</scope>
    <optional>true</optional>
  </dependency>
</dependencies>

Step 2 — Install and prepare PostgreSQL

Option A: Local install

Option B: Docker (quickest)

docker run --name restaurant_postgres -e POSTGRES_PASSWORD=your_password -p 5432:5432 -d postgres:14

Create a database and user

-- inside psql (\c to connect), or any SQL client
CREATE DATABASE restaurant_db;
CREATE USER restaurant_user WITH ENCRYPTED PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE restaurant_db TO restaurant_user;

Step 3 — Configure Spring (YAML)

Put the base configuration in src/main/resources/application.yml and keep secrets in an optional application-local.yml that is imported by the base file.

application.yml

spring:
  datasource:
    url: jdbc:postgresql://localhost:5432/restaurant_db
    username: restaurant_user
  config:
    import: optional:application-local.yml

  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true
    properties:
      hibernate:
        dialect: org.hibernate.dialect.PostgreSQLDialect
jwt:
  expiration: 86400000 # (1 day in ms)

server:
  port: 8080

application-local.yml

spring:
  datasource:
    password: ${POSTGRES_PASSWORD:default_db_password}
jwt:
  secret: ${JWT_SECRET:default_jwt_secret}

Why this split?


Step 4 — Run and verify

  1. Export environment variables (optional but recommended):
    export POSTGRES_PASSWORD=your_password
    export JWT_SECRET=dev_jwt_secret
    
  2. Start the app:
    ./mvnw spring-boot:run
    
  3. Watch the logs for a successful connection to PostgreSQL and Hibernate schema update messages.

Common issues

That’s it. Your application is now bootstrapped with the right dependencies, a running PostgreSQL, and a working YAML configuration.