skip to content

Config Client & Import

The client imports configuration from the server at startup, with fail-fast and retry options, and those values override local files. Knowing the precedence — and the migration off the legacy bootstrap context — is the practical part.

part ofSpring Frameworkoverview, primer and where to startread it →
on this pageshow

questions

5

How does a Spring Boot application connect to a Spring Cloud Config Server using spring.config.import, and what does the configserver: prefix do?

level: juniorimportance: must knowfreq 78%

answer

  1. spring.config.import=configserver:
  2. spring-cloud-starter-config dependency
  3. default URI localhost:8888
  4. name + profile + label resolve config
  5. optional: prefix to tolerate missing server

basics

~10 s

Add the spring-cloud-starter-config dependency, then set spring.config.import=configserver:http://localhost:8888 in application.yml. On startup the app fetches its properties from that Config Server before creating beans.

solid answer

~40 s

Since Spring Boot 2.4 / Spring Cloud 2020.0, you add spring-cloud-starter-config and declare spring.config.import=configserver: in application.properties or application.yml. The configserver: prefix is a ConfigData location handled by Spring Cloud; it tells Boot to reach out to the Config Server during the normal environment-loading phase and pull down that application's property sources. The URL can be given inline (configserver:http://config:8888) or omitted, in which case spring.cloud.config.uri (default http://localhost:8888) is used. The server resolves which properties to send using the app's name (spring.application.name), active profiles, and label. This replaced the old bootstrap.yml approach — no separate bootstrap context is needed anymore; it all happens through Boot's standard ConfigData import mechanism.

code

yaml · 11 lines
yaml
# application.yml (client)
spring:
  application:
    name: orders          # -> server serves orders-<profile>.yml
  profiles:
    active: prod
  config:
    import: "configserver:http://config-server:8888"
  cloud:
    config:
      label: main          # git branch/tag on the server

go deeper

for a junior

Know the property name spring.config.import=configserver: and that the starter dependency is required.

for a middle

Explain how name/profile/label select the returned config and the optional: prefix.

for a senior

Contrast the ConfigData import with the legacy bootstrap approach and know the resolver/loader classes involved.

for a principal

Reason about failure modes at startup, default URIs across environments, and standardizing the import config across a fleet of services.

## What problem this solves Spring Cloud Config **Server** is a central service that stores configuration (typically backed by a Git repo). A **Config Client** is any Spring Boot app that fetches its properties from that server at startup instead of hard-coding them locally. This gives you one place to manage config across many services and environments. ## The modern mechanism: spring.config.import Starting with **Spring Boot 2.4** and **Spring Cloud 2020.0 (Ilford)**, the client connects using Boot's **ConfigData API** via the property: ``` spring.config.import=configserver:http://localhost:8888 ``` - `spring.config.import` is a **core Spring Boot** property for importing additional configuration from external locations (files, config trees, and — with Spring Cloud on the classpath — a Config Server). - The `configserver:` prefix is a **ConfigData location**. Spring Cloud Config registers a `ConfigServerConfigDataLocationResolver` and a `ConfigServerConfigDataLoader` (through `META-INF/spring.factories`) that recognize this prefix and know how to call the server. - Everything happens during Boot's **normal Environment preparation** — no separate application context. ## Required dependency ``` org.springframework.cloud:spring-cloud-starter-config ``` Without it, `configserver:` is an unknown location and startup fails. ## How the server picks what to return The server resolves configuration from three coordinates the client sends: - **application** = `spring.application.name` (defaults to `application`) - **profile** = active profiles (`spring.profiles.active`) - **label** = Git branch/tag (`spring.cloud.config.label`, default is the server's configured default, often `main`) So an app named `orders` with profile `prod` receives properties merged from files like `orders-prod.yml`, `orders.yml`, `application-prod.yml`, `application.yml` on the server side. ## The URL - Inline: `spring.config.import=configserver:http://config:8888` - Or leave it empty (`configserver:`) and set `spring.cloud.config.uri=http://config:8888`. The default URI is `http://localhost:8888`. ## Optional import By default, if the location can't be loaded the app **fails to start**. Prefix with `optional:` to tolerate a missing/unreachable server: ``` spring.config.import=optional:configserver:http://localhost:8888 ``` ## Gotcha: this is NOT bootstrap anymore Older tutorials put config in `bootstrap.yml` and rely on a bootstrap context. Since 2.4 that is legacy and off by default. If you see `bootstrap.yml`, the project is either using the legacy mechanism (re-enabled explicitly) or is following outdated docs.

  • What replaced bootstrap.yml, and why was the change made?
    The spring.config.import mechanism (Boot 2.4 / Cloud 2020.0). It removed the need for a separate bootstrap ApplicationContext, unifying remote config loading into Spring Boot's standard ConfigData environment-preparation lifecycle, which is simpler and more predictable.
  • If you set spring.config.import=configserver: with no URL, where does it connect?
    To spring.cloud.config.uri, which defaults to http://localhost:8888.

saying these in an interview costs you the question

  • Claiming you still must use bootstrap.yml in current Spring Cloud versions
  • Thinking the client reads Git directly instead of calling the Config Server over HTTP
  • Forgetting spring-cloud-starter-config is required for the configserver: prefix to work

context

open as a page

What do spring.cloud.config.fail-fast and the retry settings do, and how are they wired together on the client?

level: middleimportance: must knowfreq 70%

basics

~20 s

fail-fast=true makes the app refuse to start if it cannot reach the Config Server. Adding spring-retry and Spring AOP lets it retry the connection a few times (with backoff) before giving up, controlled by spring.cloud.config.retry.* properties.

open as a page

Explain the difference between the ConfigData import mechanism and the legacy bootstrap context for Config Client, and how you'd re-enable bootstrap.

level: seniorimportance: should knowfreq 52%

basics

~20 s

Old versions created a separate 'bootstrap' application context from bootstrap.yml to fetch config before the main app. Since Spring Boot 2.4 that's replaced by spring.config.import handled inside the normal startup. To use the old way you add spring-cloud-starter-bootstrap or set spring.cloud.bootstrap.enabled=true.

open as a page

When properties come from both the Config Server and the client's local application.yml, which wins, and how can you change that?

level: seniorimportance: should knowfreq 58%

basics

~10 s

By default the Config Server's properties take precedence over the client's local application.yml, so central config overrides local defaults. You can flip this with flags like spring.cloud.config.override-none=true so local values win instead.

open as a page

Design a resilient Config Client startup: reconcile fail-fast, retry, optional:, and precedence for a service that must not boot with wrong config but should survive Config Server restarts. What trade-offs do you weigh?

level: principalimportance: nice to knowfreq 34%

basics

~20 s

Use a non-optional configserver: import with fail-fast=true plus spring-retry so brief outages are retried but a truly missing server aborts startup. Keep secrets from env vars winning via override-system-properties=false, and let central config override local defaults.

open as a page