Feign应用

one piece
• 阅读 468

Maven依赖

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

API服务 接口类:value值为对应微服务服务名

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@FeignClient(value = "a-server", path = TestApi.mapping, contextId = TestApi.mapping)
public interface TestApi {

   static String mapping="api/test";


   @RequestMapping(value="/getName",method = RequestMethod.POST)
   public String getName();
}

Server服务 接口调用实现,接口请求路径需与api中接口路劲一致

package com.a.web;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/test")
@Slf4j
public class TestController {

    @PostMapping("/getName")
    public String getName(){
        return "one piece";
    }

}
点赞
收藏
评论区
推荐文章

暂无数据

one piece
one piece
Lv1
入春才七日,离家已二年。
文章
0
粉丝
0
获赞
0
热门文章

暂无数据