记录使用@RequestHeader 报错sun.reflect.generics.reflectiveObjects.TypeVariableIm问题

文章讲述了在使用Feign进行接口调用时,由于未指定RequestHeader参数的Map泛型类型导致的ClassCastException。解决方案是明确指定Map的泛型为<String,String>。
摘要由CSDN通过智能技术生成

问题背景:

	@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);
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值