願望從傳統彈簧(非引導)訪問尤里卡也由簡單的像@EnableEureka和@EnableFeignClient
這是最接近我能得到它的工作。這個例子是在尤里卡例子可以在Git的樞紐
public class EurekaConfiguration {
private static ApplicationInfoManager applicationInfoManager;
private static EurekaClient eurekaClient;
private static synchronized ApplicationInfoManager initializeApplicationInfoManager(
EurekaInstanceConfig instanceConfig) {
if (applicationInfoManager == null) {
InstanceInfo instanceInfo = new EurekaConfigBasedInstanceInfoProvider(instanceConfig).get();
applicationInfoManager = new ApplicationInfoManager(instanceConfig, instanceInfo);
}
return applicationInfoManager;
}
private static synchronized EurekaClient initializeEurekaClient(ApplicationInfoManager applicationInfoManager,
EurekaClientConfig clientConfig) {
if (eurekaClient == null) {
eurekaClient = new DiscoveryClient(applicationInfoManager, clientConfig);
}
return eurekaClient;
}
public static EurekaClient getEurekaClient()
{
ApplicationInfoManager applicationInfoManager = initializeApplicationInfoManager(new MyDataCenterInstanceConfig());
EurekaClient client = initializeEurekaClient(applicationInfoManager, new DefaultEurekaClientConfig());
return eurekaClient;
}
}
我的客戶
String vipAddress = "NLPService";
InstanceInfo nextServerInfo = null;
try {
nextServerInfo = EurekaConfiguration.getEurekaClient().getNextServerFromEureka(vipAddress, false);
} catch (Exception e) {
System.err.println("Cannot get an instance of example service to talk to from eureka");
System.exit(-1);
}
System.out.println("Found an instance of example service to talk to from eureka: "
+ nextServerInfo.getVIPAddress() + ":" + nextServerInfo.getPort());
String serviceBaseURL = "http://"+ nextServerInfo.getHostName()
+":"+nextServerInfo.getPort();
String nlpServiceURL = serviceBaseURL +"/nlp";
RestTemplate restTemplate = new RestTemplate();
NLPInputToBeTransformed input = new NLPInputToBeTransformed();
input.setInputText(" Test Input ");
NLPResponse nlpResponse = restTemplate.postForObject
(nlpServiceURL, input, NLPResponse.class, new HashMap<>());
System.out.println(" Service Response " + nlpResponse.getTags());
檢查'@ EnableDiscoveryClient'註釋,發現該進口和複製該到自己的項目配置。 –