0Pricing
Spring Boot 4 Microservices & REST APIs · Aula

Clientes de configuração

Consuma a configuração centralizada nos serviços.

Clientes de configuração é uma aula grátis de Spring Boot 4 Microservices & REST APIs no CoddyKit. Esta é a aula 3 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Spring Boot 4 Microservices & REST APIs, e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Spring Boot 4 Microservices & REST APIs inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

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

Perguntas Frequentes

A aula “Clientes de configuração” é grátis?

Sim — o texto completo de “Clientes de configuração” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Spring Boot 4 Microservices & REST APIs, atualize para CoddyKit PRO. O curso de Spring Boot 4 Microservices & REST APIs inclui 4 aulas no total.

O que vou aprender em “Clientes de configuração”?

Consuma a configuração centralizada nos serviços. Você pratica Spring Boot 4 Microservices & REST APIs com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Spring Boot 4 Microservices & REST APIs?

Nenhuma experiência prévia é necessária. Spring Boot 4 Microservices & REST APIs no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 3 de 4.

Quanto tempo leva a aula “Clientes de configuração”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Spring Boot 4 Microservices & REST APIs?

Sim. Cada aula de Spring Boot 4 Microservices & REST APIs inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. O servidor de configuração
  2. Configuração respaldada pelo Git
  3. Clientes de configuração
  4. Atualizando a configuração em tempo de execução
← Voltar para Spring Boot 4 Microservices & REST APIs