0Pricing
Spring Boot 4 Microservices & REST APIs · Lesson

Config Clients

Consume centralized config in services.

Config Clients is a free Spring Boot 4 Microservices & REST APIs lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Spring Boot 4 Microservices & REST APIs learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

Turning a service into a client

A microservice becomes a Config Client by adding the client starter and telling it where the Config Server is. It then fetches its config at startup.

Adding the client dependency

Add spring-cloud-starter-config to the service.

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

spring.config.import

Modern Spring Boot uses spring.config.import to point at the Config Server, replacing the old bootstrap.yml approach.

# application.yml of the client
spring:
  application:
    name: orders
  config:
    import: "configserver:http://localhost:8888"

How the name maps to config

The client's spring.application.name selects which files the server returns. Name it orders and you get orders.yml (plus shared and profile files).

Selecting a profile

The active profile decides which profile-specific file is layered on top. Set it as usual.

spring:
  profiles:
    active: prod
# -> server returns orders.yml + orders-prod.yml merged

Optional vs required import

By default the import is required - the app fails to start if the server is down. Mark it optional: to allow startup with local config as fallback.

spring:
  config:
    import: "optional:configserver:http://localhost:8888"

Using the fetched values

Once imported, remote properties behave like any other - inject with @Value or bind to a @ConfigurationProperties class.

@Component
public class GreetingService {
    @Value("${app.greeting}")
    private String greeting; // value comes from the config server
}

Type-safe binding

For groups of related settings, bind to a class. This is cleaner and validated.

@ConfigurationProperties(prefix = "app")
public class AppProps {
    private String greeting;
    // getters/setters
}

Discovering the server (optional)

Instead of a hardcoded URL, the client can find the Config Server via a discovery service (Eureka). Enable discovery-first lookup and reference the server by service id.

spring:
  cloud:
    config:
      discovery:
        enabled: true
        service-id: config-server

Fail-fast and retry

Enable fail-fast so a client refuses to start with missing config, and add the retry starter so transient server outages are retried instead of crashing the client.

spring:
  cloud:
    config:
      fail-fast: true
      retry:
        max-attempts: 6

Property precedence

Remote config from the server generally takes precedence over the client's local application.yml, so central values win - keep only safe defaults locally.

Quick Check

Check your client-setup knowledge.

Recap

You wired up a client:

  • Add spring-cloud-starter-config
  • Point at the server with spring.config.import
  • spring.application.name + active profile select the files
  • Use optional:, fail-fast and retry to control startup behavior

Frequently asked questions

Is the “Config Clients” lesson free?

Yes — the full text of “Config Clients” is free to read here on the web, and the Spring Boot 4 Microservices & REST APIs course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Spring Boot 4 Microservices & REST APIs course, upgrade to CoddyKit PRO.

What will I learn in “Config Clients”?

Consume centralized config in services. You practise Spring Boot 4 Microservices & REST APIs with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Spring Boot 4 Microservices & REST APIs?

No prior experience is required. Spring Boot 4 Microservices & REST APIs on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Config Clients” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Spring Boot 4 Microservices & REST APIs lesson?

Yes. Every Spring Boot 4 Microservices & REST APIs lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. The Config Server
  2. Git-Backed Configuration
  3. Config Clients
  4. Refreshing Configuration at Runtime
← Back to Spring Boot 4 Microservices & REST APIs