今天写feign调用的时候发现个问题,本来写法是这样的
public interface TestClient {
@RequestLine("GET /test/param")
JSONObject getTest(@RequestParam("param") List<String> params);
}
这是我习惯的写法,专门有个feign工厂类来生成对应的feignclient,
@Configuration
public class TestFactory {
@Bean("testClient")
public TestClient getTestClient(){
return customFeignBuilder.target(TestClient.class, "http://localhost:8020");
}
}
feignBuilder是我单独写的config,这种情况下请求会报错,接收方也拿不到参数,后来发现这种写法只支持把@RequestParam注解换为@QueryMap,通过一个map来传递参数。feign参数传递
但是如果你用了feignClient注解的话,上边那种写法是没问题的
@FeignClient(name = "test",url = "http://localhost:8026",configuration = CustomFeignBuilder.class)
public interface TestClient {
@GetMapping(value = "/test/param")
JSONObject test(@RequestParam("param") String param);
}
就是不通过工厂类来生成feign client,上边两个文件替换成下边这种写法,这种情况下接收方就能拿到参数。很奇怪。。。
切记,发请求设置参数时@RequestParam和@FeignClient搭配着一起使用才可以。单独@RequestLine只能使用@QueryMap和@RequestBody.