- Sammy Tran. (11 May 2023). Using Postgres Effectively in Spring Boot Applications. HackerNoon.
- Spring Initialzr.
- Podman Desktop
-
Open the Podman Desktop application.
-
Download the latest postgres image:
podman pull postgres
- Create and run the postgres container:
podman run --name postgres-db -e POSTGRES_PASSWORD=password -p 5432:5432 -d postgres
- Connect to the postgres server:
podman exec -it postgres-db psql -U postgres
- Create the new database:
CREATE DATABASE springwebdb OWNER postgres;
- Connect to the database:
\c springwebdb
- From another terminal, start the web service using:
mvn spring-boot:run
- Test the connection by sending a GET request using curl:
curl -s localhost:8080/employees
- Create an employee by sending a POST request:
curl -s -X POST localhost:8080/employees \
-H "Content-Type: application/json" \
-d '{"firstName": "foo", "lastName": "bar", "dateOfBirth": "2023-05-04"}'
- Verify using curl:
curl -s localhost:8080/employees
- Switch to the postgres terminal and verify again using psql:
SELECT * FROM employees;