1.导包

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

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

2.编写Client类

@FeignClient(value = "TestClient ",url = "${TestClient}")
public interface TestClient {

    @RequestMapping(method = RequestMethod.GET, headers = {"Content-Type=application/json"})
    Map test(@RequestParam String url); //传参
}

3.启动类中添加注解

@EnableFeignClients(
        clients = {
                Test1.class
        }
)

4.调用方法

@Autowired
private TestClient testClient;

@Test
public void getData(){
   Map data = testClient.test("https://www.jufb.cn/");
   System.out.println(data);
}

最后修改:2022 年 05 月 24 日
如果觉得我的文章对你有用,请随意赞赏