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);
}
2 条评论
不错不错,我喜欢看 https://www.237fa.com/
博主真是太厉害了!!!