Spring Boot Tutorial 0/110 lessons ~6 min read Lesson 10

    Configuration

    Configuration is how an app behaves differently in dev, staging and prod without code changes.

    Course progress0%
    Focus
    4 guided sections
    Practice signal
    Examples included
    Career prep
    Foundation builder

    Introduction

    Configuration is how an app behaves differently in dev, staging and prod without code changes. Spring Boot reads from a precedence chain: command-line args > env vars > application-{profile}.yml > application.yml > defaults.

    Understanding the topic

    Three ways to read config:

    • @Value("${stripe.api-key}") — single property; OK for ad-hoc.
    • @ConfigurationProperties(prefix = "stripe") — type-safe binding to a record/class. Preferred.
    • Environment bean — programmatic lookup.

    Informative example

    Type-safe config with a record:

    ts
    @ConfigurationProperties(prefix = "stripe")
    @Validated
    public record StripeProps(
    @NotBlank String apiKey,
    @NotNull URI baseUrl,
    @DefaultValue("10s") Duration timeout
    ) {}
    # application.yml
    stripe:
    api-key: ${STRIPE_API_KEY}
    base-url: https://api.stripe.com
    timeout: 5s

    Best practices

    • Inject secrets via env vars; never commit them.
    • Use @ConfigurationProperties + @Validated — fail fast on missing values.
    • Prefer application.yml over .properties — nested, comments, multi-line.
    Ready to mark this lesson complete?Track your journey across the entire course.