spring-cloud-feign 使用@RequetParam报错QueryMap parameter must be a Map: class java.lang.String
这里使用spring-cloud-start-feign: 1.2.6 REALEASE版本,依赖管理器版本是 Camden.SR6
出错的原因是@RequestParam的value为empty时,参数会被当作Map来处理
org.springframework.cloud.netflix.feign.annotation.RequestParamParameterProcessor
代码如下:
@Override public boolean processArgument(AnnotatedParameterContext context, Annotation annotation) { RequestParam requestParam = ANNOTATION.cast(annotation); String name = requestParam.value(); if (emptyToNull(name) != null) { context.setParameterName(name); MethodMetadata data = context.getMethodMetadata(); Collection<String> query = context.setTemplateParameter(name, data.template().queries().get(name)); data.template().query(name, query); } else { // supports `Map` types MethodMetadata data = context.getMethodMetadata(); data.queryMapIndex(context.getParameterIndex()); } return true; }
说明spring-cloud-feign处理@RequestParam和Spring mvc的不一样,Spring mvc在@RequestParam的value为空的时候反射得到参数的名字作为value
解决方案: 给@RequestParam加上value