Describe the bug
Please provide details of the problem, including the version of Spring Cloud that you
are using.
It is my first time facing this and it is kind of confusing. Every time where I have used @PathVariable, I just matched the /{parameter} with the actual parameter on the method so I wouldn't have to do it like this @PathVariable("parameter") Integer parameter, but instead I would do it like @PathVariable Integer parameter for /{parameter}, but when doing the same thing while using OpenFeign there was an error saying " PathVariable annotation was empty on param 0." which is not really true because I have annotated my parameter as a @PathVariable.
This fails and throws 'PathVariable annotation was empty on param 0.'
@FeignClient(name = "fraud-service")
public interface FraudClient {
@GetMapping("api/v1/fraud-check/{customerId}")
FraudCheckResponse isFraudster(@PathVariable Integer customerId);
}
This works, correct me if I am wrong but when specifying the method parameter with the same name as the endpoint parameter, there is no need to specify the @PathVariable("thisHere") but I can just use @PathVariable Integer customerId without using the parenthesis on the @PathVariable to specify a value.
@FeignClient(name = "fraud-service")
public interface FraudClient {
@GetMapping("api/v1/fraud-check/{customerId}")
FraudCheckResponse isFraudster(@PathVariable("customerId") Integer customerId);
}
Not sure if it is a bug or just a confusion from my side but I just wanted to let you guys know and clarify it for my self as well. Have a great one guys :)
Comment From: OlgaMaciaszek
Hello @eno-lc. It should, indeed, work and, as far as I can say, it does. Please see a sample branch that works without any issues. If you're still experiencing any issues with it, please provide a minimal, complete, verifiable example that reproduces the issue.
Comment From: avdi-vrellaku
Hi @OlgaMaciaszek, reaching out from a colleague device here. Having the same issue on a different machine as well, not sure why. I'll provide the link to a repository where you can check the following application/microservice as we get the following error:
Caused by: java.lang.IllegalStateException: PathVariable annotation was empty on param 0.
at feign.Util.checkState(Util.java:129) ~[feign-core-10.12.jar:na]
at org.springframework.cloud.openfeign.annotation.PathVariableParameterProcessor.processArgument(PathVariableParameterProcessor.java:51) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
at org.springframework.cloud.openfeign.support.SpringMvcContract.processAnnotationsOnParameter(SpringMvcContract.java:299) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:111) ~[feign-core-10.12.jar:na]
at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:194) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:62) ~[feign-core-10.12.jar:na]
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:151) ~[feign-core-10.12.jar:na]
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:49) ~[feign-core-10.12.jar:na]
at feign.Feign$Builder.target(Feign.java:269) ~[feign-core-10.12.jar:na]
at org.springframework.cloud.openfeign.DefaultTargeter.target(DefaultTargeter.java:30) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:419) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:371) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:235) ~[spring-cloud-openfeign-core-3.0.3.jar:3.0.3]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1249) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1191) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:582) ~[spring-beans-5.3.13.jar:5.3.13]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:542) ~[spring-beans-5.3.13.jar:5.3.13]
... 42 common frames omitted
See the following repository: https://github.com/avdi-vrellaku/microservices-issue-on-empty-param-PathVariable
Clients package contains the FeignClient that I've provided in the bug description
Customer package is where the FeignClient is called
Fraud package contains the controller that is called via the feign client.
Comment From: OlgaMaciaszek
Hello @avdi-vrellaku, will take a look. Please learn how to properly format code and logs.
Comment From: OlgaMaciaszek
Hello @avdi-vrellaku @eno-lc - please provide a minimal sample, with only the modules and classes necessary to reproduce your issue.
Comment From: spring-cloud-issues
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.
Comment From: spring-cloud-issues
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.
Comment From: kaszuster
I know this is old and closed. Just wanted to leave this here, to help anyone searching for this error.
https://github.com/OpenFeign/feign/issues/2337