如何调用spring cloud eureka服务

发布网友

我来回答

1个回答

热心网友

比如有一个服务如下
@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);
}
}

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com