Hot questions for Spring Cloud Feign Client

Top 10 Java Open Source / Spring / Spring Cloud Feign Client


I created a simple Feign Client with Spring Boot like this:

public interface GreetingClient {
    String greeting(@RequestParam String name);

But when I try just to start an application I get an error:

java.lang.IllegalStateException: RequestParam.value() was empty on parameter 0

First I didn't understand what is the reason and googled a lot but didn't find an answer. Almost excidentely I figured out that it works if to write request param name explicitly:

@RequestParam("name") String name

So my question: is it a bug or could it be configured to not write request params names explicitly?


Both Spring MVC and Spring cloud feign are using the same ParameterNameDiscoverer - named DefaultParameterNameDiscoverer to find parameter name. It tries to find the parameter names with the following step.

First, it uses StandardReflectionParameterNameDiscoverer. It tries to find the variable name with reflection. It is only possible when your classes are compiled with -parameters.

Second, if it fails, it uses LocalVariableTableParameterNameDiscoverer. It tries to find the variable name from the debugging info in the class file with ASM libraries.

The difference between Spring MVC and Feign occurs here. Feign uses above annotations (like @RequestParam) on methods of Java interfaces. But, we use these on methods of Java classes when using Spring MVC. Unfortunately, javac compiler omits the debug information of parameter name from class file for java interfaces. That's why feign fails to find parameter name without -parameter.

Namely, if you compile your code with -parameters, both Spring MVC and Feign will succeed to acquire parameter names. But if you compile without -parameters, only Spring MVC will succeed.

As a result, it's not a bug. it's a limitation of Feign at this moment as I think.



I recently used netflix feign along with ribbon which was quite useful.

An Example of this is:

@FeignClient(name = "ldap-proxy")
public interface LdapProxyClient  { 
    @RequestMapping(path = "/ldap-proxy/v1/users/{userNameOrEMail}", produces = MediaType.APPLICATION_JSON_VALUE, method = RequestMethod.GET)
    LdapUser search(@PathVariable("userNameOrEMail") String userNameOrEMail);

However, at some point I thought that instead of having to code all these definitions by hand (for an existing webservice), that I should see if a tool existed.

I stumbled across saw that there are examples in which clients are generated, e.g. .

However, once I looked closely at the imports I noticed the following:

import feign.Feign;

Netflix's opensource solution on the other hand has package names:

Additionally, I noticed that both use ribbon if available, but Netflix's notation is much cleaner with a lot happenning in the background. E.g. the @FeignClient annotation class javadoc states:

  • Annotation for interfaces declaring that a REST client with that interface should be * created (e.g. for autowiring into another component). If ribbon is available it will be * used to load balance the backend requests, and the load balancer can be configured * using a @RibbonClient with the same name (i.e. value) as the feign client.

However in the Feign.feign documentation (at ) I see:

RibbonClient overrides URL resolution of Feign's client, adding smart routing and resiliency capabilities provided by Ribbon.

Integration requires you to pass your ribbon client name as the host part of the url, for example myAppProd.

> MyService api =
> Feign.builder().client(RibbonClient.create()).target(MyService.class,
> "https://myAppProd");
So my questions are:
  1. what is the history/relationship and differences between the two?
  2. what are the pros and cons of each?

Are they completely different projects with no relation, or did netflix just fork/utilize OpenFeign and modify it to be within their integrated cloud solution? Essentially, did netflix just acquire and integrate different technologies like Discovery, ribbon, and feign from open-source projects?

Answer: is a part of Spring Cloud Netflix project which is a part of Spring Cloud.

Spring Cloud uses OpenFeign under the hood. It extends it to support Spring MVC annotations and makes it a first-class citizen in the Spring Environment by providing integrations for Spring Boot apps through autoconfiguration.

From the documentation:

Feign is a declarative web service client. Spring Cloud adds support for Spring MVC annotations and for using the same HttpMessageConverters used by default in Spring Web. Spring Cloud integrates Ribbon and Eureka to provide a load balanced http client when using Feign.

Note that in the documentation there is a link to OpenFeign project.

So if you use Spring Boot - it is better and easier to use Spring Cloud OpenFeign integrations.

See also the source code.


The microservice I'm writting needs to communicate to other microservices in our platform. On that attempt, the ideal solution for us is Spring Cloud Netflix Feign, implemeting a @FeignClient.

However, I'm facing the exception below when I try an @Autowired ReviewProvider:

Exception (cause)

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type '' available

public interface ReviewProvider {

    @RequestMapping(path = "sessions", method = POST)
    ReviewSessionDTO createSession();


@ContextConfiguration(classes = AppEntry.class)
@AutoConfigureTestDatabase(replace = Replace.NONE)
public class ReviewProviderTest {

    private ReviewProvider provider;
    private Class<? extends ReviewProvider> providerClass;

    public void setup() {
        providerClass = provider.getClass();

    public void classAnnotations() {
        assertEquals("http://metadata-reviews", providerClass.getAnnotation(FeignClient.class).value());

    public void createSession() throws Exception {
        final Method method = providerClass.getDeclaredMethod("createSession");

        final RequestMapping mapping = method.getAnnotation(RequestMapping.class);
        assertEquals("sessions", mapping.path());
        assertEquals(0, method.getParameters().toString());


Seems like there is not anything out there yet about the solution to this stuff...

Here is what I did to solve this: 1. Add this annotation to your test class:

@ImportAutoConfiguration({RibbonAutoConfiguration.class, FeignRibbonClientAutoConfiguration.class, FeignAutoConfiguration.class})

Try it, if it does not work, you might need the @EnableFeignClients annotation on your main program config


Using spring-mvc annotations, how can I define an @FeignClient that can POST form-url-encoded?


Use form encoder for feign: and your feign configuration can look like this:

class CoreFeignConfiguration {

  private ObjectFactory<HttpMessageConverters> messageConverters

  Encoder feignFormEncoder() {
      new FormEncoder(new SpringEncoder(this.messageConverters))

Then, the client can be mapped like this:

@FeignClient(name = 'client', url = 'localhost:9080', path ='/rest', configuration = CoreFeignConfiguration)
interface CoreClient {

    @RequestMapping(value = '/business', method = POST, consumes = MediaType.APPLICATION_FORM_URLENCODED)
    @Headers('Content-Type: application/x-www-form-urlencoded')
    void activate(Map<String, ?> formParams)


It's my Feign interface

        configuration = FeignSimpleEncoderConfig.class
public interface MpiClient {

    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity<String> getPAReq(@QueryMap Map<String, String> queryMap

and my custom configuration

public class FeignSimpleEncoderConfig {
    public static final int FIVE_SECONDS = 5000;

    public Logger.Level feignLogger() {
        return Logger.Level.FULL;

    public Request.Options options() {
        return new Request.Options(FIVE_SECONDS, FIVE_SECONDS);

    public Feign.Builder feignBuilder() {
        return Feign.builder()
                .encoder(new FormEncoder());

If I send request like this I see that my request send Content-Type: application/json;charset=UTF-8. But if I set content type

consumes = "application/x-www-form-urlencoded"

I've this error message

feign.codec.EncodeException: Could not write request: no suitable HttpMessageConverter found for request type [java.util.HashMap] and content type [application/x-www-form-urlencoded]
    at ~[spring-cloud-netflix-core-1.1.7.RELEASE.jar:1.1.7.RELEASE]

How to send POST request, I think I should make something more with Encoder. Thanks for your help.


First of all you should change your Feign interface like this:

@FeignClient (
    configuration = FeignSimpleEncoderConfig.class
public interface MpiClient {
   @RequestMapping(method = RequestMethod.POST)
   ResponseEntity<String> getPAReq(Map<String, ?> queryMap);

Then you should set the encoder during feign configuration:

public class FeignSimpleEncoderConfig {
    public Encoder encoder() {
        return new FormEncoder();


I have a restful service calling an external service using Spring Cloud Feign client

@FeignClient(name = "external-service", configuration = FeignClientConfig.class)
public interface ServiceClient {

    @RequestMapping(value = "/test/payments", method = RequestMethod.POST)
    public void addPayment(@Valid @RequestBody AddPaymentRequest addPaymentRequest);

    @RequestMapping(value = "/test/payments/{paymentId}", method = RequestMethod.PUT)
    public ChangePaymentStatusResponse updatePaymentStatus(@PathVariable("paymentId") String paymentId,
            @Valid @RequestBody PaymentStatusUpdateRequest paymentStatusUpdateRequest);


I noticed the following failure 3-4 times in the last 3 months in my log file:

json.ERROR_RESPONSE_BODY:Connection refused executing POST http://external-service/external/payments json.message:Send Payment Add Payment Failure For other reason: {ERROR_RESPONSE_BODY=Connection refused executing POST http://external-service/external/payments, EVENT=ADD_PAYMENT_FAILURE, TRANSACTION_ID=XXXXXXX} {} json.EVENT:ADD_PAYMENT_FAILURE json.stack_trace:feign.RetryableException: Connection refused executing POST http://external-service/external/payments at feign.FeignException.errorExecuting( at feign.SynchronousMethodHandler.executeAndDecode( at feign.SynchronousMethodHandler.invoke( at feign.ReflectiveFeign$FeignInvocationHandler.invoke(

Is it possible to add Spring Retry on a Feign client. What I wanted to annotate the addPayment operation with

@Retryable(value = {feign.RetryableException.class }, maxAttempts = 3, backoff = @Backoff(delay = 2000, multiplier=2))

But this is not possible, what other options do I have?


You can add a Retryer in the FeignClientConfig

public class FeignClientConfig {

    public Retryer retryer() {
        return new Custom();


class Custom implements Retryer {

    private final int maxAttempts;
    private final long backoff;
    int attempt;

    public Custom() {
        this(2000, 3);

    public Custom(long backoff, int maxAttempts) {
        this.backoff = backoff;
        this.maxAttempts = maxAttempts;
        this.attempt = 1;

    public void continueOrPropagate(RetryableException e) {
        if (attempt++ >= maxAttempts) {
            throw e;

        try {
        } catch (InterruptedException ignored) {

    public Retryer clone() {
        return new Custom(backoff, maxAttempts);

Updated with sample Retryer example config based on the Retryer.Default.