You don't really need your own implementation of the FeignRequestInterceptor as there is already BasicAuthRequestInterceptor in the feign.auth package that does exactly the same.

That being said, you basically have almost everything set up already. All is left to do is to define the basicAuthRequestInterceptor bean with specific username and password:

@Bean
public RequestInterceptor basicAuthRequestInterceptor() {
    return new BasicAuthRequestInterceptor("username", "password");
}
Answer from Aleksandr Erokhin on Stack Overflow
Top answer
1 of 3
25

You don't really need your own implementation of the FeignRequestInterceptor as there is already BasicAuthRequestInterceptor in the feign.auth package that does exactly the same.

That being said, you basically have almost everything set up already. All is left to do is to define the basicAuthRequestInterceptor bean with specific username and password:

@Bean
public RequestInterceptor basicAuthRequestInterceptor() {
    return new BasicAuthRequestInterceptor("username", "password");
}
2 of 3
12

I know the thread is a bit old but wanted to give some explanation on what's happening here.

If you'd like to customize your Feign requests, you can use a RequestInterceptor. This can be a custom implementation or you can reuse what's available in the Feign library, e.g. BasicAuthRequestInterceptor.

How to register it? Well, there are 2 ways to do it depending on how you use Feign.

If you're using plain Feign without Spring, then you gotta set the interceptor to the Feign builder. An example is here.

Feign.builder()
     .requestInterceptor(new MyCustomInterceptor())
     .target(MyClient.class, "http://localhost:8081");

If you're using Spring Cloud OpenFeign and you use the @FeignClient annotation to construct your clients, then you have to create a bean from your RequestInterceptor by either defining it as a @Component or as a @Bean in one of your @Configuration classes. Example here.

@Component
public class MyCustomInterceptor implements RequestInterceptor {
    @Override
    public void apply(RequestTemplate template) {
        // do something
    }
}

Also, you can check out one of my articles in this topic, maybe that clears it up better: Customizing each request with Spring Cloud Feign

🌐
OneUptime
oneuptime.com › home › blog › how to implement custom feign interceptors
How to Implement Custom Feign Interceptors
January 30, 2026 - package com.example.interceptors; import feign.RequestInterceptor; import feign.RequestTemplate; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @Component public class ApiKeyInterceptor implements RequestInterceptor { // Load API key from application.yml or environment variable @Value("${service.api-key}") private String apiKey; @Value("${service.api-key-header:X-API-Key}") private String headerName; @Override public void apply(RequestTemplate template) { // Always add the API key for service-to-service auth template.header(headerName, apiKey); } }
🌐
Javacodemonk
javacodemonk.com › feign-requestinterceptor-in-spring-boot-cbe5d967
Feign RequestInterceptor in Spring Boot
July 14, 2020 - All we need to do is to create a Bean of type RequestInterceptor inside a config class and provide that configuration to FeignClient.
🌐
Medium
medium.com › @aravindcsebe › mastering-feign-requestinterceptor-from-authentication-to-advanced-use-cases-d78fad055af5
Mastering Feign RequestInterceptor: From Authentication to Advanced Use Cases | by Spring Boot Simplified | Medium
February 9, 2026 - How it works: Every time Service B calls Service A through the Feign client, the AuthInterceptor automatically adds the authentication token to the request headers. Now that we understand the basics, let’s explore what else we can accomplish with RequestInterceptor.
🌐
Javadoc.io
javadoc.io › static › io.github.openfeign › feign-core › 10.12 › feign › RequestInterceptor.html
RequestInterceptor (Feign Core 10.12 API)
Once interceptors are applied, Target.apply(RequestTemplate) is called to create the immutable http request sent via Client.execute(Request, feign.Request.Options). For example: public void apply(RequestTemplate input) { input.header("X-Auth", currentToken); } Configuration RequestInterceptors ...
🌐
Medium
medium.com › @sachinsindhu › feign-client-request-interceptor-pit-falls-f7f08ff61b74
Feign client Request Interceptor Pit falls | by Sachin Sindhu | Medium
September 11, 2023 - We can leverage template.feignTarget().type() to find which client made this request to identify which interceptor logic to apply. @Component @RequiredArgsConstructor public class CommonRequestInterceptor implements RequestInterceptor { private final InterceptorProvider interceptorProvider; @Override public void apply(RequestTemplate template) { CustomRequestInterceptor interceptor = interceptorProvider.getInterceptorOfClientType(template.feignTarget().type()); if (interceptor != null) { interceptor.apply(template); } } If we define all our interceptors as component/service we can use spring context as a factory itself because all beans are already there in application context.
🌐
Spring Cloud
cloud.spring.io › spring-cloud-netflix › multi › multi_spring-cloud-feign.html
7. Declarative REST Client: Feign
Collection<RequestInterceptor> SetterFactory · Creating a bean of one of those type and placing it in a @FeignClient configuration (such as FooConfiguration above) allows you to override each one of the beans described. Example: @Configuration public class FooConfiguration { @Bean public Contract feignContract() { return new feign.Contract.Default(); } @Bean public BasicAuthRequestInterceptor basicAuthRequestInterceptor() { return new BasicAuthRequestInterceptor("user", "password"); } } This replaces the SpringMvcContract with feign.Contract.Default and adds a RequestInterceptor to the collection of RequestInterceptor.
🌐
Tabnine
tabnine.com › home › code library
Code Library - Tabnine
July 25, 2024 - Get the answers and suggestions you need from our AI code assistant. Get started in minutes with a free 90 day trial of Tabnine Pro.
🌐
GitHub
github.com › OpenFeign › feign › blob › master › core › src › main › java › feign › RequestInterceptor.java
feign/core/src/main/java/feign/RequestInterceptor.java at master · OpenFeign/feign
* Zero or more {@code RequestInterceptors} may be configured for purposes such as adding headers to · * all requests. No guarantees are given with regards to the order that interceptors are applied. * Once interceptors are applied, {@link Target#apply(RequestTemplate)} is called to create the · * immutable http request sent via {@link Client#execute(Request, feign.Request.Options)}. <br> * <br> * For example: <br> * * <pre> * public void apply(RequestTemplate input) { * input.header(&quot;X-Auth&quot;, currentToken); * } * </pre> * * <br> * <br> * <b>Configuration</b><br> * <br> * {@code RequestInterceptors} are configured via {@link Feign.Builder#requestInterceptors}. <br> * <br> * <b>Implementation notes</b><br> * <br> * Do not add parameters, such as {@code /path/{foo}/bar } in your implementation of {@link ·
Author: OpenFeign
Find elsewhere
🌐
Javadoc.io
javadoc.io › static › io.github.openfeign › feign-core › 10.10.1 › feign › RequestInterceptor.html
RequestInterceptor (Feign Core 10.10.1 API)
Once interceptors are applied, Target.apply(RequestTemplate) is called to create the immutable http request sent via Client.execute(Request, feign.Request.Options). For example: public void apply(RequestTemplate input) { input.header("X-Auth", currentToken); } Configuration RequestInterceptors ...
🌐
Javadoc.io
javadoc.io › static › io.github.openfeign › feign-core › 11.0 › feign › RequestInterceptor.html
RequestInterceptor (Feign Core 11.0 API)
Once interceptors are applied, Target.apply(RequestTemplate) is called to create the immutable http request sent via Client.execute(Request, feign.Request.Options). For example: public void apply(RequestTemplate input) { input.header("X-Auth", currentToken); } Configuration RequestInterceptors ...
🌐
Javadoc.io
javadoc.io › doc › io.github.openfeign › feign-core › 10.12 › feign › RequestInterceptor.html
RequestInterceptor - feign-core 10.12 javadoc
Latest version of io.github.openfeign:feign-core · https://javadoc.io/doc/io.github.openfeign/feign-core · Current version 10.12 · https://javadoc.io/doc/io.github.openfeign/feign-core/10.12 · package-list path (used for javadoc generation -link option) https://javadoc.io/doc/io.github.openfeign/feign-core/10.12/package-list ·
🌐
Arnoldgalovics
arnoldgalovics.com › feign-interceptor
Customizing each request with Spring Cloud Feign interceptor – Arnold Galovics
February 19, 2018 - @FeignClient(name = "translation", url = "http://localhost:9001") public interface TranslationClient { @RequestMapping("/message") MessageResponse message(); }
🌐
Baeldung
baeldung.com › home › spring › spring cloud › introduction to spring cloud openfeign
Introduction to Spring Cloud OpenFeign | Baeldung
February 19, 2026 - ... @Bean public RequestInterceptor requestInterceptor() { return requestTemplate -> { requestTemplate.header("user", username); requestTemplate.header("password", password); requestTemplate.header("Accept", ContentType.APPLICATION_JSON.getMimeType()); }; }...
🌐
Medium
medium.com › @IlyasKeser › feignclient-interceptor-for-bearer-token-oauth-f45997673a1
FeignClient Interceptor for Bearer Token/OAuth | by Ilyas Keser | Medium
October 20, 2019 - Here an example for an interceptor as a Spring component. @Component public class FeignClientInterceptor implements RequestInterceptor { private static final String AUTHORIZATION_HEADER="Authorization"; private static final String TOKEN_TYPE = "Bearer"; @Override public void apply(RequestTemplate requestTemplate) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails details = (OAuth2AuthenticationDetails) authentication.getDetails(); requestTemplate.header(AUTHORIZATION_HEADER, String.format("%s %s", TOKEN_TYPE, details.getTokenValue())); } } }
🌐
CodingTechRoom
codingtechroom.com › question › enhance-your-feign-client-adding-a-request-interceptor
How to Add a Request Interceptor to a Feign Client - CodingTechRoom
import feign.RequestInterceptor; ... public class FeignClientConfig { @Bean public RequestInterceptor requestInterceptor() { return template -> { template.header("Authorization", "Bearer my-token"); // You can also access and modify request method, query params ...
🌐
Medium
medium.com › @saiteja-erwa › feign-client-requestinterceptors-2435f4e5cfb1
Feign Client: RequestInterceptors - Saiteja Erwa - Medium
May 18, 2024 - Zero or more RequestInterceptors ... in which interceptors are applied. ... use-case: Example: If service-A is consuming with service-B using feignClient 1....
🌐
Medium
medium.com › @babalolaopedaniel › how-to-use-feign-client-with-interceptors-for-authentication-in-a-spring-boot-application-71d46ba89c06
How to Use Feign Client with Interceptors for Authentication in a Spring Boot Application | by Babalola Opeyemi | Medium
December 29, 2024 - If you followed the example tutorial project above promptly, you should have no errors, and when you do run these curl commands either individually or using a bash script, you should get valid data. The above project shows how a simple Feign interceptor can be used. However, there are other(complex?) ways in which the interceptor can be used, and some of them are; ... public class OAuth2RequestInterceptor implements RequestInterceptor { private final String accessToken; @Override public void apply(RequestTemplate template) { template.header("Authorization", "Bearer " + accessToken); } }
🌐
DEV Community
dev.to › tarcalia › feign-clients-with-multiple-interceptors-in-spring-boot-hh2
Feign Clients with Multiple Interceptors in Spring Boot - DEV Community
June 18, 2025 - public class TrackingIdInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { template.header("X-Tracking-ID", UUID.randomUUID().toString()); } } public class AuthTokenInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { template.header("X-Auth-Token", "mockedTokenValue"); } } public class LibraryProvidedInterceptor implements RequestInterceptor { @Override public void apply(RequestTemplate template) { template.header("X-Library", "libValue"); } } Now we plug everything together in a configuration class: @Configuration public class FeignConfig { @Bean public RequestInterceptor compositeInterceptor() { return new CompositeRequestInterceptor( new AuthTokenInterceptor(), new TrackingIdInterceptor(), new LibraryProvidedInterceptor() ); } }