OpenFeign客户端调用报错target values must be absolute
在使用OpenFeign调用远程服务器接口时,报错提示如下:
原因在于实现类需要指定一个host
主机地址
public class PlanUpdateServiceImpl implements PlanUpdateService { private String host; public PlanUpdateServiceImpl(String host) { this.host = host; } @Override public String updatePlanContent(String planContentRequest) { PlanUpdateService planUpdateService = OkHttpFeign.target(PlanUpdateService.class, this.host); return planUpdateService.updatePlanContent(planContentRequest); } }
而当我们创建该实体类给host
传值时如下:
PlanUpdateService planUpdateService = new PlanUpdateServiceImpl("localhost:8081");
没有携带http://
导致的,我们修改如下即可解决:
PlanUpdateService planUpdateService = new PlanUpdateServiceImpl("http://localhost:8081");