Configuration

About

In a Spring Boot application, OpenFeign clients are auto-configured by default when using the spring-cloud-starter-openfeign dependency. However, enterprise-grade applications often need fine-grained control over aspects like:

  • Connection timeouts

  • Logging level

  • Interceptors (headers, authentication)

  • Retry mechanisms

  • Custom encoders/decoders

To enable such control, Spring allows custom configuration classes, either globally or per client.

Types of Configuration

Configuration Scope
Description

Global Configuration

Applies to all Feign clients in the application

Per-Client Configuration

Applies only to a specific Feign client using @FeignClient(configuration = ...)

Global Configuration

Global configuration in OpenFeign refers to settings that apply across all Feign clients in your Spring Boot application. This is especially useful when:

  • You want a standard behavior across microservices.

  • You don't want to repeat configurations for each Feign client.

  • You’re handling common concerns like timeouts, retries, logging, etc.

Instead of configuring each client separately, you define a default configuration block in application.yml or application.properties.

Spring Cloud OpenFeign reads the global configuration from the feign.client.config.default section. It uses this block to initialize every client, unless a specific override is defined for that client.

Example: application.yml

If we name a client (like account-service), that block overrides the default:

Available Global Settings

Property
Description

connect-timeout

Timeout for establishing connection (ms)

read-timeout

Timeout for waiting for response (ms)

loggerLevel

Log verbosity: NONE, BASIC, HEADERS, or FULL

retryer.period

Base interval between retries

retryer.maxPeriod

Maximum wait time between retries

retryer.maxAttempts

Max number of retry attempts

errorDecoder

Fully qualified class name of custom error decoder

requestInterceptors

List of fully qualified interceptor class names

decoder / encoder

Custom decoder or encoder bean class names (if overriding globally)

Per-Client Configuration

Per-client configuration in OpenFeign allows you to define custom settings for individual Feign clients, giving you fine-grained control over how each client behaves.

This is useful when certain services:

  • Have different timeout requirements

  • Need specific headers or interceptors

  • Require unique retry policies

  • Should use a different encoder, decoder, or error handler

Rather than applying a one-size-fits-all setup (like in global config), you tailor each client based on its communication pattern, SLAs, or external API behavior.

How It Works ?

OpenFeign allows us to configure each client separately in our application.yml or application.properties, using the name of the client defined in @FeignClient(name = "...").

We can also attach a Java config class using the configuration attribute of @FeignClient.

Configuration in application.yml

This ensures:

  • account-service is faster and retries quickly.

  • payment-service allows for longer response times and lower log verbosity.

Using Java Configuration Class

We can create a dedicated configuration class:

And link it like this:

Available Settings

Setting
Where to Use

connect-timeout

application.yml/properties

read-timeout

Same as above

loggerLevel

application.yml or Java config class

retryer

Java config class or YAML block

errorDecoder

Java class implementing ErrorDecoder

requestInterceptors

One or more RequestInterceptor beans

encoder / decoder

Custom classes to override default behavior

Logging

1. Enable Feign Logging in application.yml

This ensures all Feign internals (request, response, codec, auth) are visible.

2. Configuring Feign Logger in Spring Boot

Feign has four logging levels we can set per client:

  • NONE – No logging (default).

  • BASIC – Logs request method, URL, response status.

  • HEADERS – Logs BASIC + request/response headers.

  • FULL – Logs everything: headers, body, metadata.

a) Global Config

b) Per-Client Config

Last updated