Spring Boot 4 cheatsheet

Spring Boot 4: Configuration

5 common Spring Boot 4 tasks.

Change the port

Set the HTTP port in application.properties.

server.port=8081

Run with a profile

Activate application-prod.properties for one run.

java -jar app.jar --spring.profiles.active=prod

Set a profile with an environment variable

Environment variables override properties, which suits containers.

SPRING_PROFILES_ACTIVE=prod java -jar app.jar

Bind properties to a class

Map properties with the prefix app to a typed class.

@ConfigurationProperties(prefix = "app")
public record AppProperties(String name, int timeout) {}

Configure a database

Point the app at PostgreSQL. Use real credentials from the environment.

spring.datasource.url=jdbc:postgresql://localhost:5432/mydb
spring.datasource.username=${DB_USER}
spring.datasource.password=${DB_PASSWORD}

Was this page helpful?