Skip to main content
1:1 mock interviews with Sumit, scored on a real hiring rubric.Book a slot →
TOPIC 6 OF 7 · 2 MIN READ

Configuration, Properties and Profiles

Spring Boot reads configuration from properties files, YAML, environment variables and command-line arguments in a defined order, and switches settings per environment with profiles. Interviewers ask about precedence, @ConfigurationProperties and handling secrets.

What you will learn

  • Know the property source order
  • Bind settings with @ConfigurationProperties
  • Use profiles for dev, test and prod
  • Keep secrets out of the repository

Key concepts

Precedence

Higher wins: command-line args → environment variables (SPRING_DATASOURCE_URL) → application-{profile}.yml → application.yml → defaults. Environment variables are the usual way to configure containers.

@ConfigurationProperties

Binds a group of properties to a typed class or record with validation, preferred over many @Value fields.

Profiles

spring.profiles.active=prod loads application-prod.yml and activates beans with @Profile("prod").

Step by step

Typed configuration

# application.yml
payments:
  provider: razorpay
  timeout: 3s
  retry:
    max-attempts: 3

@ConfigurationProperties(prefix = "payments")
@Validated
public record PaymentProperties(@NotBlank String provider, Duration timeout, Retry retry) {
    public record Retry(@Min(1) int maxAttempts) {}
}

@SpringBootApplication
@ConfigurationPropertiesScan
public class App { ... }

Examples

Profiles and secrets

# application-prod.yml
spring:
  datasource:
    url: ${DB_URL}
    username: ${DB_USER}
    password: ${DB_PASSWORD}   # injected by the platform, never committed

@Bean
@Profile("!prod")
CommandLineRunner seedDemoData(UserRepository repo) { return args -> repo.saveAll(demoUsers()); }

Practise it

Try these without looking back. If you can explain each one out loud, you are ready for this question.

  • Run the same jar with two profiles and print the active settings at startup.
  • Override one property with an environment variable and explain the naming rule (relaxed binding).

Interview questions

What interviewers ask next on this topic. Answer out loud first, then open the model answer.

@Value vs @ConfigurationProperties?

@Value injects single values and supports SpEL, fine for one or two settings. @ConfigurationProperties binds a whole group into a typed object with validation, relaxed binding and IDE metadata, better for anything structured.

Summary

Externalise configuration, know that command line and environment variables override files, bind groups with @ConfigurationProperties, use profiles per environment and inject secrets at runtime.

Stuck on this one? Talk to Sumit.

Keys: F focus mode · ← → previous / next topic · Esc leave focus