Feign

作者: 蓝色_fea0 | 来源:发表于2018-08-22 22:40 被阅读10次

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

相关文章

网友评论

      本文标题:Feign

      本文链接:https://www.haomeiwen.com/subject/hweuiftx.html