为了账号安全,请及时绑定邮箱和手机立即绑定

如何调用spring cloud eureka服务?

/ 猿问

如何调用spring cloud eureka服务?

HUH函数 2018-11-21 22:18:33

如何调用spring cloud eureka服务


查看完整描述

1 回答

?
慕虎7371278

比如有一个服务如下
@EnableEurekaClient
@SpringBootApplication
@RestController
public class EurekaClientApplication {

@Value("${server.port}")
String port;
@RequestMapping("/hi")
public String home(@RequestParam String name) {
return "hi "+name+",i am from port:" +port;
}

public static void main(String[] args) {
SpringApplication.run(EurekaClientApplication.class, args);

}
}

这个服务名为:EurekaClient
----------------------------------------------------------------------------------------------
调用采用以下方式:
定义一个借口,注解@FeignClient(value = "EUREKACLIENT")

@Service
@FeignClient(value = "EUREKACLIENT")//服务名
public interface SchedualServiceHi {

@RequestMapping(value = "/hi",method = RequestMethod.GET)
String sayHiFromClientOne(@RequestParam(value = "name") String name);

}

@RestController
public class HiController {

@Autowired
SchedualServiceHi schedualServiceHi;

@RequestMapping(value = "/hi",method = RequestMethod.GET)
public String sayHi(@RequestParam String name){
return schedualServiceHi.sayHiFromClientOne(name);
}
}



查看完整回答
反对 2018-12-11

添加回答

回复

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信