问题背景:
@RequestMapping(value = "/invoicePoolController/invoiceAuth", method = RequestMethod.POST)
@FRemark(log = true)
Object invoiceAuth(@RequestBody Map<String, Object> param, @RequestHeader MultiValueMap multiValueMap);
发起feign调用时,使用了@RequestHeader注解表示该map是请求头参数
但是没有指定Map泛型类型,所以报错:
Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
at feign.Contract$BaseContract.checkMapKeys(Contract.java:171)
at feign.Contract$BaseContract.checkMapString(Contract.java:152)
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:136)
at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:207)
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:62)
at feign.hystrix.HystrixDelegatingContract.parseAndValidateMetadata(HystrixDelegatingContract.java:47)
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:151)
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:49)
at feign.hystrix.HystrixFeign$Builder.target(HystrixFeign.java:70)
at org.springframework.cloud.openfeign.HystrixTargeter.targetWithFallbackFactory(HystrixTargeter.java:66)
at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:53)
at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:352)
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:388)
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:361)
at org.springframework.cloud.openfeign.FeignClientsRegistrar.lambda$registerFeignClient$0(FeignClientsRegistrar.java:246)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.obtainFromSupplier(AbstractAutowireCapableBeanFactory.java:1235)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:556)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:516)
... 29 common frames omitted
解决办法:指定泛型
@RequestMapping(value = "/invoicePoolController/invoiceAuth", method = RequestMethod.POST)
@FRemark(log = true)
Object invoiceAuth(@RequestBody Map<String, Object> param, @RequestHeader MultiValueMap<String, String> multiValueMap);