I found a bug in the version Greenwich.RELEASE with Spring Boot 2.1.x and contract SpringMvcContract:
API:
public interface ApiRestTest { @GetMapping(path = "/apiRest") public Object find(@RequestParam(value = "clientId") Long clientId); }
BUILDER:
Feign.builder().contract(new SpringMvcContract()) .encoder(new JacksonEncoder(objectMapperApiRestClient)) .decoder(new JacksonDecoder(objectMapperApiRestClient)) .retryer(new Retryer.Default()) .options(new Options()) .requestInterceptor(new CustomRequestInterceptor()) .errorDecoder(new CustomErrorDecoder()) .target(ApiRestTest.class, url);
ERROR:
java.lang.NoSuchMethodError: feign.RequestTemplate.method(Lfeign/Request$HttpMethod;)Lfeign/RequestTemplate; at org.springframework.cloud.openfeign.support.SpringMvcContract.processAnnotationOnMethod(SpringMvcContract.java:184) at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:95) at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:147) at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:64) at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:146) at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:53) at feign.Feign$Builder.target(Feign.java:198) at feign.Feign$Builder.target(Feign.java:194)
I have tested with the versions Greenwich.M1, Greenwich.M2, Greenwich.M3, Greenwich.RC1 and it works correctly. From version Greenwich.RC2 it no work.
What is happening? How can I solve it?
Thx!
Comment From: spencergibb
Please try with Greenwich. SR4
Comment From: jbazp
I have tried with the version Greenwich.SR4 of spring-cloud and with version 2.1.10.RELEASE of spring-boot and it does not work. Only works with version Greenwich.RC1 and previous versions.
I have analyzed in which version it stopped working and I saw that it was when you released the version Greenwich.RC2 of spring cloud that contained the version v2.1.0.RC3 of spring-cloud-openfeign. Here is the comparison between the versions:
https://github.com/spring-cloud/spring-cloud-openfeign/compare/v2.1.0.RC2...v2.1.0.RC3
This line added in file SpringMvcContract.java causes the failure:
data.template().method(Request.HttpMethod.valueOf(methods[0].name()));
Comment From: spencergibb
What version of feign do you have, since our builds would fail?
Comment From: jbazp
I am using version 2.1.4.RELEASE of spring-cloud-starter-openfeign. The error occurs when calling to:
Feign.builder().contract(new SpringMvcContract()) .encoder(new JacksonEncoder(objectMapperApiRestClient)) .decoder(new JacksonDecoder(objectMapperApiRestClient)) .retryer(new Retryer.Default()) .options(new Options()) .requestInterceptor(new CustomRequestInterceptor()) .errorDecoder(new CustomErrorDecoder()) .target(ApiRestTest.class, url);
It does not have to fail because the input parameters are variable, try with this api:
public interface ApiRestTest { @GetMapping(path = "/apiRest") public Object find(@RequestParam(value = "clientId") Long clientId); }
Comment From: jbazp
Sorry! I have already solved it, I had a problem with dependencies
Comment From: klnlakshmi
Hi JBAZP, I am also getting the same error. What was the dependency correction you did?
Comment From: jbazp
@klnlakshmi, I changed coordinates maven, I used old maven coordinates. I changed com.netflix.feign by io.github.openfeign:
Old maven coordinates:
<dependency>
<groupId>com.netflix.feign</groupId>
<artifactId>feign-jackson</artifactId>
</dependency>
New maven coordinates:
<dependency>
<groupId>io.github.openfeign</groupId>
<artifactId>feign-jackson</artifactId>
</dependency>