猿问
下载APP

spring cloud服务之间怎么调用

海绵宝宝撒
浏览 409回答 1
1回答

宝慕林4294392

比如有一个服务如下12345678910111213141516171819@EnableEurekaClient@SpringBootApplication@RestControllerpublic 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")12345678@Service@FeignClient(value = "EUREKACLIENT")//服务名public interface SchedualServiceHi {     @RequestMapping(value = "/hi",method = RequestMethod.GET)    String sayHiFromClientOne(@RequestParam(value = "name") String name); }1234567891011@RestControllerpublic class HiController {     @Autowired    SchedualServiceHi schedualServiceHi;     @RequestMapping(value = "/hi",method = RequestMethod.GET)    public String sayHi(@RequestParam String name){        return schedualServiceHi.sayHiFromClientOne(name);    }}
打开App,查看更多内容
随时随地看视频慕课网APP
我要回答