如何调用spring cloud eureka服务
发布网友
发布时间:2022-04-23 03:16
我来回答
共1个回答
热心网友
时间:2023-09-24 17:03
比如有一个服务如下
@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 SchealServiceHi {
@RequestMapping(value = "/hi",method = RequestMethod.GET)
String sayHiFromClientOne(@RequestParam(value = "name") String name);
}
@RestController
public class HiController {
@Autowired
SchealServiceHi schealServiceHi;
@RequestMapping(value = "/hi",method = RequestMethod.GET)
public String sayHi(@RequestParam String name){
return schealServiceHi.sayHiFromClientOne(name);
}
}