运行了7001,7002与8001,80,访问http://localhost/consumer/dept/list时报出如下错误,只有在访问list与add时报下面错误,访问get时正常。
网上查询了一番,捣腾了一番,都没法解决。。。直到我看到了自己的DeptConsumerController.java中代码,发现自己的代码是这样的:
private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-DEPT"; @RequestMapping("/consumer/dept/add") public boolean add(Dept dept){ return restTemplate.postForObject(REST_URL_PREFIX+"dept/add", dept, Boolean.class); } @RequestMapping( value = "/consumer/dept/get/{id}") public Dept get(@PathVariable("id") Long id){ return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id,Dept.class); } @RequestMapping("/consumer/dept/list") public List<Dept> list(){ return restTemplate.getForObject(REST_URL_PREFIX+"dept/list", List.class); }我特么都要哭了。。。也就是说我的错误是因为自己的add与list方法中的getForObject()中第一个参数写错了,正确写法如下:
private static final String REST_URL_PREFIX = "http://SPRINGCLOUD-PROVIDER-DEPT"; @RequestMapping("/consumer/dept/add") public boolean add(Dept dept){ return restTemplate.postForObject(REST_URL_PREFIX+"/dept/add", dept, Boolean.class); } @RequestMapping( value = "/consumer/dept/get/{id}") public Dept get(@PathVariable("id") Long id){ return restTemplate.getForObject(REST_URL_PREFIX+"/dept/get/"+id,Dept.class); } @RequestMapping("/consumer/dept/list") public List<Dept> list(){ return restTemplate.getForObject(REST_URL_PREFIX+"/dept/list", List.class); }折腾了快两小时了,竟然是因为这样的错误。。真的被自己蠢哭了。