前言
记录下Feign
脱离Ribbon
的使用
环境
Spring Cloud Hoxton.SR9 + Spring Cloud Alibaba 2.2.6.RELEASE
具体实现
TestBaiduFeignClient.java
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;
/**
* feign 脱离 ribbon 的使用方式
* name 必须指定,可随意
*/
@FeignClient(name = "baidu", url = "http://www.baidu.com")
public interface TestBaiduFeignClient {
@GetMapping("")
public String index();
}
TestController.java
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
public class TestController {
private final TestBaiduFeignClient testBaiduFeignClient;
/**
* feign脱离ribbon的使用
* @return
*/
@GetMapping("baidu")
public String baiduIndex() {
return testBaiduFeignClient.index();
}
}
- 接口调用
http://localhost:8010/baidu