Client Feign with Spring Boot: RequestParam.value () was empty for parameter 0

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

@FeignClient("spring-cloud-eureka-client")
public interface GreetingClient {
    @RequestMapping("/greeting")
    String greeting(@RequestParam String name);
}

      

But when I try to run the application, I get an error:

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

      

At first I did not understand what the reason was, and googled a lot but did not find an answer. Almost by accident, I realized that this works by writing the name of the request parameter explicitly:

@RequestParam("name") String name

      

So my question is, is this a bug or can it be configured to not explicitly record the names of the query parameters?

+8


source to share


2 answers


Spring MVC and Spring Feign use the same ParameterNameDiscoverer

name DefaultParameterNameDiscoverer

to look up the parameter name. It tries to find the parameter names in the next step.

First, it uses StandardReflectionParameterNameDiscoverer

. It tries to find a variable name with reflection. This is only possible when your classes are compiled with -parameters

.

Second, if it fails, it uses LocalVariableTableParameterNameDiscoverer

. It tries to find the name of the variable from the debug information in the class file with the ASM libraries.



The difference between Spring MVC and Feign comes in here. Feign uses the above annotations (for example @RequestParam

) for Java interface methods. But we use them in Java class methods when using Spring MVC. Unfortunately the javac compiler is missing parameter name debug information from the class file for java interfaces . This is why feign cannot find the parameter name without -parameter

.

Namely, if you compile your code with -parameters

Spring MVC and Feign will get the parameter names. But if you compile without -parameters

, only Spring MVC will succeed.

As a result, this is not an error. this is Feign's limitation at the moment, I think.

+11


source


Just use String greeting(@RequestParam("name") String name);



    @FeignClient("spring-cloud-eureka-client")
    public interface GreetingClient {
       @RequestMapping("/greeting")
       String greeting(@RequestParam("name") String name);
    }

      

+9


source







All Articles