私はこれをGoogle GuiceのProvider
実装を使用して解決しました。ここ サンプル
public class Main {
public static AccountService get() {
return Feign.builder()
.contract(new JAXRSContract())
.decoder(new GsonDecoder())
.target(AccountService.class, "http://localhost:9090");
}
static class RestClientProvider implements Provider<AccountService> {
RestClientProvider() {
}
@Override
public AccountService get() {
return Main.get();
}
}
static class AppInjector extends AbstractModule {
@Override
protected void configure() {
Provider<AccountService> prov = new RestClientProvider();
bind(AccountService.class).toProvider(prov);
}
}
public static void main (String... args) {
Injector inj = Guice.createInjector(new AppInjector());
AccountService ac = inj.getInstance(AccountService.class);
Account a = ac.getAccountByName("Mihir");
System.out.println(a.getName());
}
}
あります