Template for Spring Boot 3 application

Includes web-server on port 9080 with REST API under /api/v1 (articles CRUD and paged list). OpenAPI/Swagger describes request/response examples and error shapes.
Prerequisites:
How to build:
mvn clean install
Build Docker image with application inside:
docker build ./ -t backend-template-app
Start application using a starting script:
Use run.bat script
Start application (vs in-memory DB H2) by running executable jar:
java -jar target/spring-boot-3-template-0.0.1-SNAPSHOT.jar \
--spring.datasource.url=jdbc:h2:mem:testdb \
--spring.datasource.username=sa \
--spring.datasource.password=password \
--spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect \
--spring.datasource.driver-class-name=org.h2.Driver
Same thing but using Spring profile to determine properties:
java -jar target/spring-boot-3-template-0.0.1-SNAPSHOT.jar \
--spring.profiles.active=dev
Start application (vs in-memory DB H2) using Maven:
mvn spring-boot:run -Dspring-boot.run.arguments="\
--spring.datasource.url=jdbc:h2:mem:testdb \
--spring.datasource.username=sa \
--spring.datasource.password=password \
--spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect \
--spring.datasource.driver-class-name=org.h2.Driver"
Same thing but using Spring profile to determine properties:
mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=dev
Start Docker containers (application & Postgres DB) using existing images:
docker-compose up
Build images, force recreate and start Docker containers (application & Postgres DB):
docker-compose up --build --force-recreate
Stop and delete containers:
docker-compose down
Link for quick check:
Useful CURL commands
New article addition:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "title": "Some tittle", "text": "Some text", "author": "Pushkin" }' -X POST http://localhost:9080/api/v1/articles
Get existing article:
curl -i http://localhost:9080/api/v1/articles/1
Update existing article:
curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "title": "Another tittle" }' -X PATCH http://localhost:9080/api/v1/articles/2
Get a list of articles with pagination support:
curl -i 'http://localhost:9080/api/v1/articles?size=2&page=4&sort=author,DESC'
Deletion of article:
curl -i -X DELETE http://localhost:9080/api/v1/articles/1
Configuration and environment variables
| Variable |
Purpose |
DB_URL |
JDBC URL (required when using Postgres) |
DB_USER |
Database user |
DB_PASSWORD |
Database password |
logging.file.path |
Log directory (default logs; see logback-spring.xml) |
Spring profile dev selects in-memory H2 (application-dev.properties). Default application.properties expects Postgres-related variables.
Deployment
- Runnable JAR:
mvn clean package, then run java -jar target/spring-boot-3-template-0.0.1-SNAPSHOT.jar with the right profile and DB_* (or --spring.profiles.active=dev for H2).
- Docker image:
docker build ./ -t backend-template-app (the build expects target/*.jar to exist—run mvn package first).
- Docker Compose:
docker-compose up --build brings up Postgres and the service with healthchecks and optional .env.
Security (production)
REST APIs ship without Spring Security—suitable for local development only. Before a public deployment, add authentication (e.g. Spring Security or an API gateway), keep secrets in environment variables (see .env.example for Compose), and restrict Actuator in production (RECOMMENDATIONS.md).
Video with project description

The same project but with usage of Spring Boot 2 available here
评论