在使用Springcloud搭建服务时,然后远程服务调用FeignClient(继承API Service服务发现,有实现接口,注解了@RestController)接口,
如
api工程包
@RequestMapping
public interface TestService{
String test(@RequestParam("userId") Integer userId,
RequestParam("userId") Integer atestparam,
RequestParam("userId") Integer btestparam);
}
impl工程包
@RestController
public class TestServiceImpl implements TestService{
@Override
public String test(Integer userId,Integer atestparam,Integer btestparam){
return "success";
}
}
web工程包
启动类注解使用feign进行rpc调用 @EnableFeignClients
在service层
@FeignClient("test-impl")//实现包 在注册中心的名称
public class TestServiceFeign extends TestService{//需要引用API工程包
//此时已继承过来方法
}
此时我犯了一个极大的错误,由于工程是改造,很多方法我是Ctrl+C Ctrl+V 过来的
出现了下面这个错误
Caused by: java.lang.UnsupportedOperationException: null
at java.util.Collections$UnmodifiableCollection.add(Collections.java:1055) ~[na:1.8.0_201]
at org.springframework.cloud.openfeign.support.FeignUtils.addTemplateParameter(FeignUtils.java:60) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.openfeign.support.SpringMvcContract$SimpleAnnotatedParameterContext.setTemplateParameter(SpringMvcContract.java:460) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.openfeign.annotation.RequestParamParameterProcessor.processArgument(RequestParamParameterProcessor.java:69) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.openfeign.support.SpringMvcContract.processAnnotationsOnParameter(SpringMvcContract.java:292) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at feign.Contract$BaseContract.parseAndValidateMetadata(Contract.java:110) ~[feign-core-10.1.0.jar:na]
at org.springframework.cloud.openfeign.support.SpringMvcContract.parseAndValidateMetadata(SpringMvcContract.java:188) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at feign.Contract$BaseContract.parseAndValidatateMetadata(Contract.java:66) ~[feign-core-10.1.0.jar:na]
at feign.hystrix.HystrixDelegatingContract.parseAndValidatateMetadata(HystrixDelegatingContract.java:46) ~[feign-hystrix-10.1.0.jar:na]
at feign.ReflectiveFeign$ParseHandlersByName.apply(ReflectiveFeign.java:154) ~[feign-core-10.1.0.jar:na]
at feign.ReflectiveFeign.newInstance(ReflectiveFeign.java:52) ~[feign-core-10.1.0.jar:na]
at feign.Feign$Builder.target(Feign.java:251) ~[feign-core-10.1.0.jar:na]
at org.springframework.cloud.openfeign.HystrixTargeter.target(HystrixTargeter.java:55) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.loadBalance(FeignClientFactoryBean.java:238) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getTarget(FeignClientFactoryBean.java:267) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.cloud.openfeign.FeignClientFactoryBean.getObject(FeignClientFactoryBean.java:247) ~[spring-cloud-openfeign-core-2.1.1.RELEASE.jar:2.1.1.RELEASE]
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:171) ~[spring-beans-5.1.9.RELEASE.jar:5.1.9.RELEASE]
... 30 common frames omitted
浪费了我大半天时间来解决这个问题,写这个博客来记住警戒自己,做事情要仔细
相信在座的各位已经看出是什么原因导致这个错误了,
没错,就是API TestService 这个类中,里面参数@RequestParam("userId") 出现了三次
我已经崩溃的彻底彻底的了