SpringCloud学习

SpringCloud服务调用之Feign

2018-05-29  本文已影响0人  FlyXhc

首先pom文件中加入

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-feign</artifactId>
            <version>2.0.0.M1</version>
        </dependency>

新建Client

@FeignClient(name = "CLIENT")
public interface Client {

    /**
     * 获取消息
     * @return
     */
    @GetMapping("/msg")
    String getMsg();
}

修改ClientController如下

@RestController
public class ClientController {

    private Logger logger = LogManager.getLogger(this.getClass());

    @Autowired
    private Client client;

    @GetMapping("/clientMsg")
    public String clientMsg(){
        String response = client.getMsg();
        logger.info("response:" + response);
        return response;
    }
}

重启服务,访问localhost:8081/clientMsg
源码地址: https://gitee.com/swlfly/SpringCloud_Learn/tree/1.3

更多技术文章可关注个人公众号: 码农Fly

公众号二维码: qrcode_for_gh_3d746d8ff050_258 (1).jpg
上一篇下一篇

猜你喜欢

热点阅读