SpringCloudLearning
SpringCloudLearning copied to clipboard
feign 方式,接口要返回List<obj>请问如何实现,
1.feign接口定义: public interface ICommonServiceApi { @RequestMapping(value = "/list",method = RequestMethod.GET) List<User> getList(@RequestHeader("count") Integer count); } 2.服务实现: @RestController public class UserCommerApiController implements ICommonServiceApi { @Override public List<User> getList(Integer count){ List<User> 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<User> getList(Integer count) { System.out.println("调取list出问题==========="); return new ArrayList<User>(); } }
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 没声明出去,请帮忙看看什么原因