Feign

2018-08-22  本文已影响10人  蓝色_fea0

1、我们需要在pom.xml里添加feign依赖

  <dependency>
         <groupId>org.springframework.cloud</groupId>
         <artifactId>spring-cloud-starter-openfeign</artifactId>
   </dependency>

在启动类里添加@EnableFeignClients 注解

2、编写一个feign client接口

package com.wuhongyu.eurekaclient2.feignclient;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient(name = "client1")
@Component
public interface Client1FeignClient {

    @GetMapping("/test")
    String test();
}

3、controller里调用接口

  @Autowired
    private Client1FeignClient client1FeignClient;

    @GetMapping("/feign")
    public String getMsg1(){
        String result = client1FeignClient.test();
        log.info("result = {}",result);
        return result;
    }

测试结果:


image.png
上一篇 下一篇

猜你喜欢

热点阅读