我有一个URL:http://localhost:8080/company,并且想使用伪装客户端调用服务。可以说我想在运行时动态地执行此操作,但是我不知道我需要自动装配哪个接口以及需要调用哪种方法。
是否可以仅通过url自动连接伪装客户端并调用给定方法?
谢谢大家的时间。
编辑: 下面的代码对于CompanySearch类调用CompanyApi服务并获取数据的效果很好。
假冒客户
@FeignClient(name = "companyClient" ,url = "http://localhost:9000")
public interface CompanyApi {
@RequestMapping(method = RequestMethod.GET,path = "/company")
Company companyInfo();
}
@FeignClient(name = "employeeClient" ,url = "http://localhost:9001")
public interface CompanyApi {
@RequestMapping(method = RequestMethod.GET,path = "/employee")
Employee employeeInfo();
}
服务方法:
@Component
public class CompanySearch {
@Autowired
CompanyApi companyApi;
@Autowired
EmployeeApi employeeApi;
public Snapshot snapshot(){
Company company = companyApi.companyInfo();
Employee employee = employeeApi.employeeInfo();
return new Snapshot(company,employee);
}
我想检查一下是否有办法伪装成这样。我可以完成此Apache的HttpClient,并希望探索Feign的等效产品。
public Snapshot snapshot(){
this.client = Feign.builder().target("http://localhost:9000/company").build();
if(client instanceof CompanyApi.class) {
Company company = ((companyApi)client).companyInfo();
}
}