0PricingLogin
Spring Boot 4 Microservices & REST APIs · Lesson

Profiles for Environments

Switch configuration per environment with profiles.

Why Profiles Exist

Real applications run in several environments — local, dev, staging, production — each needing different datasources, log levels, and feature toggles. Profiles let one codebase carry many configurations and activate the right set at runtime.

A profile is just a named label. Beans and property files can be tagged so they apply only when that profile is active.

Profile-Specific Property Files

Boot automatically loads application-{profile}.yml on top of the base application.yml. The profile file overrides matching keys while inheriting everything else.

# application.yml (base, always loaded)
spring:
  jpa:
    show-sql: false

# application-dev.yml (loaded when dev active)
spring:
  jpa:
    show-sql: true
  datasource:
    url: jdbc:h2:mem:devdb

All lessons in this course

  1. application.properties and YAML
  2. Profiles for Environments
  3. Type-Safe Configuration with @ConfigurationProperties
  4. Externalized and Override Configuration
← Back to Spring Boot 4 Microservices & REST APIs