The 30 second answer
Spring Boot combines configuration sources into one Environment, with a defined order deciding which value wins. In the usual runtime sources, command-line arguments override environment variables, which override application config files; external config takes precedence over packaged config. I can read individual values with @Value, or bind related settings to typed objects with @ConfigurationProperties. That binding supports relaxed names, so an environment variable like SPRING_DATASOURCE_URL can supply the spring.datasource.url setting.
**1. One Environment, many sources.** The docs list the order. From lowest to highest priority (shortened):
- Default properties (
SpringApplication.setDefaultProperties) @PropertySourceon@Configurationclasses- Config data files:
application.properties/.ymlinside the jar, then profile files inside the jar, then files outside the jar, then profile files outside the jar RandomValuePropertySource(random.*)- OS environment variables
- Java system properties (
-D...) - JNDI, servlet context and servlet config parameters
SPRING_APPLICATION_JSON- Command-line arguments (
--server.port=9000) - Test properties (
@SpringBootTest(properties = ...),@TestPropertySource,@DynamicPropertySource)
A lookup goes through the sources in order and returns the first match.
2. Relaxed binding. The same property can be written in different forms: spring.datasource.url in YAML, SPRING_DATASOURCE_URL as an environment variable. This is what makes Spring Boot easy to run in containers and Kubernetes.
3. Typed binding. Prefer @ConfigurationProperties over many @Value fields:
@ConfigurationProperties("payments")
@Validated
record PaymentProperties(@NotNull URI baseUrl,
@DefaultValue("2s") Duration timeout,
@DefaultValue("3") int maxRetries) { }payments:
base-url: https://pay.example
timeout: 500msRegister it with @EnableConfigurationProperties(PaymentProperties.class) or @ConfigurationPropertiesScan. Spring Boot converts types (for example 500ms to Duration), validates with Bean Validation, and fails fast at startup if a value is wrong. Spring Boot's own settings such as server.* are bound the same way; for example, ServerProperties is annotated @ConfigurationProperties("server") (ServerProperties.java L60).
4. More sources. spring.config.import can pull config trees (Kubernetes mounted secrets as files), or with extra libraries, Vault or a config server.
**@Value vs. @ConfigurationProperties:** @Value is fine for one value and supports SpEL. @ConfigurationProperties gives grouping, validation, IDE metadata, and full relaxed binding.
Debugging: the Actuator env and configprops endpoints show each value and the source it came from.
Alternate interview scenarios
"A pod ignores PAYMENT_TIMEOUT from its environment, or a ConfigMap value loses to a command-line argument. How do you trace which property source won?"
First I confirm the name maps to the property I think it does. Relaxed binding turns an environment variable into a property by lowercasing it and treating underscores as dots, so PAYMENT_TIMEOUT feeds payment.timeout, not payments.timeout or payment.timeout-ms. Then I check that the variable actually reached the process, for example with env inside the container. A ConfigMap injected as environment variables is just an OS environment variable, and the documented order puts command-line arguments, SPRING_APPLICATION_JSON and system properties above it, so a --payment.timeout argument wins by design. Finally I ask Actuator: the env endpoint for that property lists every property source that defines it in precedence order, with its origin, and configprops shows the value actually bound. Values are masked unless show-values allows them, which is the right default. The fix is to remove the higher source or move the value to the level that should win, not to add another override.
"A blank environment variable overrides a valid YAML default, or a renamed property silently falls back to its default. How do you find the broken binding?"
An environment variable set to an empty string is still a value. It sits above application.yml in the order, so it replaces the default with blank, and the env endpoint shows the environment as its origin. Unset the variable in the deployment rather than sending it empty. A renamed or mistyped key is different: nothing binds to it, so the field keeps its default and nothing fails. I protect important settings with @ConfigurationProperties plus @Validated and constraints such as @NotNull, so a missing value stops startup, and I compare the keys in the deployment with configprops. Two modules writing the same key with different casing, such as myApp.timeout and my-app.timeout, are one property after relaxed binding, so the higher-precedence source decides which value wins. I standardise on lower-case kebab form, as the docs recommend.
"LOGGING_LEVEL_ROOT has no effect, or a duration setting parses locally but fails in production. How do you diagnose it?"
For logging, LOGGING_LEVEL_ROOT maps to logging.level.root, and the docs show package levels such as LOGGING_LEVEL_ORG_SPRINGFRAMEWORK_WEB working the same way. So I check the variable reached the process and that no higher source sets logging.level.root. Environment variables are lowercased, so they cannot target a single class's logger; SPRING_APPLICATION_JSON can. For a Duration, Spring Boot accepts a plain number, meaning milliseconds unless @DurationUnit says otherwise, ISO-8601 such as PT30S, or the simple form such as 30s. If production fails, I read the raw value and its origin from the env endpoint: a value typed differently in a ConfigMap, or a different unit annotation, usually explains it.
"The Docker image has the right value, but the container uses another, a secret placeholder fails only in Kubernetes, or a native executable behaves differently from the JVM build. Build time or runtime?"
Files packaged in the jar are the lowest-priority config data. Anything set at runtime, such as environment variables, arguments or external files, overrides them, so the image's value is only a default. A Kubernetes secret mounted as files is not read automatically: it needs spring.config.import with a configtree: location, otherwise a placeholder such as a database password has no source. If the secret is injected as an environment variable, I check its name and that it exists in the pod. A GraalVM native image is a closed world: Spring's ahead-of-time processing evaluates beans at build time, so profile-specific configuration has limitations and properties that change which beans exist, such as @ConditionalOnProperty or .enabled flags, are not supported at runtime. I compare the profiles and resources used during the native build with the JVM run.
"One bean sees a changed property while another keeps the old value, or a mounted ConfigMap changes but the running app does not. How would you reload configuration safely?"
Plain Spring Boot reads configuration at startup and does not watch files. The Kubernetes docs say environment variables from a ConfigMap need a pod restart, and a ConfigMap mounted with subPath never receives updates. With Spring Cloud, a refresh publishes an EnvironmentChangeEvent that rebinds @ConfigurationProperties beans and recreates @RefreshScope beans. A singleton that copied a value through @Value at startup keeps the old value, which explains the mismatch. Spring Cloud Kubernetes can trigger reloads, with a refresh strategy for those beans or a full context restart. For anything that affects connections, pools or security, I prefer a rolling restart: it is predictable, and readiness probes protect traffic.
"After a Config Server outage, a release starts with stale defaults, or a config client reads the wrong branch. How do you prove why?"
By default a Spring Cloud Config client does not fail startup when it cannot reach the server, so the app starts with local defaults. The docs say to set spring.cloud.config.fail-fast to true, or, with spring.config.import, to omit the optional: prefix, so startup fails instead; retry settings can wait for the server. For the branch, the client requests application, profile and label. The profile comes from the active profiles and the label from spring.cloud.config.label, so I set the label explicitly per environment and check the startup log and the env endpoint for which remote property source loaded.
"How do profiles and external configuration interact?"
This version asks how the two mechanisms work together, not how to load a profile file or how to debug a single winning property. Profiles choose which beans are created (@Profile) and which profile-specific documents are added to the Environment (application-prod.properties overrides the non-profile file). External configuration then overlays those packaged defaults: environment variables, command-line arguments and files outside the jar sit higher in the documented property-source order, so a runtime value wins over a profile file inside the jar. I keep secrets out of the repository and in those higher sources, and I confirm the active profiles in the startup log (or the env endpoint) before I chase a missing property. A wrong active profile and a lower-priority file can look the same in the running app: the value you expected never entered the Environment.
Sources (13)
- Spring Boot reference: Profilesdocs.spring.io
- Spring Boot reference: Externalized configuration (property source order and profile-specific files)docs.spring.io
- Spring Boot reference: Type-safe configuration propertiesdocs.spring.io
- Spring Boot reference: Relaxed bindingdocs.spring.io
- Spring Boot reference: Binding from environment variablesdocs.spring.io
- Spring Boot reference: Converting durationsdocs.spring.io
- Spring Boot reference: Configuration treesdocs.spring.io
- Spring Boot reference: Log levels and environment variablesdocs.spring.io
- Spring Boot reference: GraalVM native images and the closed-world assumptiondocs.spring.io
- Kubernetes docs: ConfigMaps (updates, environment variables and subPath)kubernetes.io
- Spring Cloud Commons: Environment changes and refresh scopedocs.spring.io
- Spring Cloud Kubernetes: PropertySource reloaddocs.spring.io
- Spring Cloud Config: Client (fail-fast, retry, label)docs.spring.io