OpenFeign doesn't work with kotlin suspend method
See original GitHub issueI have an API interface where the methods are kotlin suspend methods:
@FeignClient(path = "/api/masker", contextId = "MaskerApi", name = Const.SERVICE, configuration = [FeignConfig::class])
interface MaskerApi {
@PostMapping("/mask")
suspend fun mask(
@Valid @RequestBody maskRequest: MaskRequest,
): RestResponse<List<CharSequence>>
@PostMapping("/matches")
suspend fun matches(
@Valid @RequestBody maskRequest: MaskRequest,
): RestResponse<List<Boolean>>
}
But when I run the program, the program throws an exception:
Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract java.lang.Object io.github.xhstormr.masker.web.api.masker.MaskerApi.matches(io.github.xhstormr.masker.model.masker.MaskRequest,kotlin.coroutines.Continuation)
Warnings:
-
at feign.Util.checkState(Util.java:121) ~[feign-core-11.7.jar:na]
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:142) ~[feign-core-11.7.jar:na]
at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:193) ~[spring-cloud-openfeign-core-3.1.0.jar:3.1.0]
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:65) ~[feign-core-11.7.jar:na]
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:151) ~[feign-core-11.7.jar:na]
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:49) ~[feign-core-11.7.jar:na]
at feign.Feign$Builder.target(Feign.java:268) ~[feign-core-11.7.jar:na]
at org.springframework.cloud.openfeign.DefaultTargeter.target(DefaultTargeter.java:30) ~[spring-cloud-openfeign-core-3.1.0.jar:3.1.0]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:373) ~[spring-cloud-openfeign-core-3.1.0.jar:3.1.0]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:421) ~[spring-cloud-openfeign-core-3.1.0.jar:3.1.0]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:396) ~[spring-cloud-openfeign-core-3.1.0.jar:3.1.0]
at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:235) ~[spring-cloud-openfeign-core-3.1.0.jar:3.1.0]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1249) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.14.jar:5.3.14]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.14.jar:5.3.14]
... 28 common frames omitted
This kotlin.coroutines.Continuation parameter is generated by the kotlin compiler at compile time, so I can’t modify this parameter, how can I tell FeignClient to ignore this Continuation parameter?
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (4 by maintainers)
Top Results From Across the Web
Asynchronous http calls with coroutines (using an http client ...
1) http client used some kind of suspending function inside while reading data over the network like suspended fun readChunkOfData() in some ...
Read more >Non-Blocking Spring Boot with Kotlin Coroutines - Baeldung
At first, please note that findAll() function is not a suspending one. However, as far as we're returning Flow, it internally calls suspending ......
Read more >Feign: Resilience and scalability for Rest clients | Medium
Create reliable Rest clients using @Feign and implement error handling strategies using circuit breaker and @ErrorDecoder for customize error messages.
Read more >Fault tolerance: Goodbye Hystrix, Hello Resilience4J!
A nice solution to prevent a cascade of failing services and to make sure that your services keep working is Resilience4J's 'circuitbreaker'.
Read more >Spring Cloud
Kotlin Lambda support ... Connection issues; Errors like c.g.cloud.sql.core. ... /actuator/pause and /actuator/resume for calling the Lifecycle methods ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@tmdgusya I see what you mean. The problem with this issue is to make FeignClient annotated classes to resolve suspend method calls.
Ok