forezp / SpringCloudLearning

《史上最简单的Spring Cloud教程源码》

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

feign 方式,接口要返回List<obj>请问如何实现,

goal578 opened this issue · comments

1.feign接口定义:
public interface ICommonServiceApi {
@RequestMapping(value = "/list",method = RequestMethod.GET)
List getList(@RequestHeader("count") Integer count);
}
2.服务实现:
@RestController
public class UserCommerApiController implements ICommonServiceApi {
@OverRide
public List getList(Integer count){
List list = new ArrayList<>();
for (int i = 0 ;i < count ;i++) {
User user = new User("jlc_" + i,i);
list.add(user);
}
return list;
}
}
3.消费者实现:
@component
@FeignClient(name = "service-user",fallback=CommonFeignServiceImpl.class )
public interface ICommonFeignService extends ICommonServiceApi{
}

public class CommonFeignServiceImpl implements ICommonFeignService{
@OverRide
public List getList(Integer count) {
System.out.println("调取list出问题===========");
return new ArrayList();
}
}

4.消费者controller实现:
@RestController
public class FeignCommonApiController {
@RequestMapping(value = "/allc",method = RequestMethod.GET)
public String feignConsumer2(){
System.out.println("测试带参数");
System.out.println(iCommonFeignService.getList(new Integer(6)).size() + "-------------------");
return "over";
}
}

最后通过 http://localhost:端口/allc 调用,报错误:
feign.FeignException: status 404 reading ICommonFeignService#getList(Integer); content:
{"timestamp":1529836681332,"status":404,"error":"Not Found","message":"No message available","path":"/list"}

感觉 /list 没声明出去,请帮忙看看什么原因