OpenFeign / feign

Feign makes writing java http clients easier
Apache License 2.0
9.49k stars 1.93k forks source link

Add documentation/exception for required java compiler flag "parameters" #2337

Open kaszuster opened 8 months ago

kaszuster commented 8 months ago

When using OpenFeign in the following way (no name attribute specified):

@RequestLine("GET /getSomething?id={id}")
String getSomething(@Param String id);

You may encounter the following exception:

... annotation was empty on param 0

This happens because @Param long catalogId is compiled as @Param long arg0. OpenFeign will then fail to read the parameter name via reflection.

To fix this, you need to pass the parameters flag to the Java compiler:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
        <parameters>true</parameters>
    </configuration>
</plugin>

After hours of research and debugging I have found this solution. Just now I found a little hint in your documentation: (if the code was compiled with -parameters flag). I would like to see that more visible or even in the exception..

kdavisk6 commented 1 month ago

Thanks for finding this. Open to pull requests to update our documentation.