工作碰到这个问题,解决后记录一下,废话不多说,直接上代码
@Data
@Configuration
@Import(FeignClientsConfiguration.class)
public class Test {
private TestService testClient;
//Feign 原生构造器
Feign.Builder builder;
//创建构造器
public Test(Decoder decoder, Encoder encoder, Client client, Contract contract) {
this.builder = Feign.builder()
.client(client)
.encoder(encoder)
.decoder(decoder)
.contract(contract);
}
public void buildFeign(String url) {
this.testClient = builder.target(TestService.class, url);
}
}
@RequestMapping(value = "test",method = RequestMethod.GET)
@ResponseBody
public void test(){
String url = "http://cyn-admin";
service.buildFeign(url);
System.out.println(service.getTestClient().dictList());
}