1、build.gradle中引入元件
compile ("org.springframework.cloud:spring-cloud-starter-config:2.1.1.RELEASE")
compile ("org.springframework.cloud:spring-cloud-starter-openfeign:2.1.3.RELEASE")
2、Application啟動類中添加注解@EnableFeignClients
3、添加 接口
url 在配置項中,也可以直接寫死例如: http://hhh.com
@Service
@FeignClient(value = "TestApiService", url = "${test.serverUrl}")
public interface TestApiService {
/**
- PostMapping中的value就是要轉發的位址
- @param param
-
@return
*/
@PostMapping(value = "/api/v1/user/role")
CommonResponse<Object> userRole(@RequestBody UserRoleParam param);
}
4、在Controller中調用即可
@Autowired
private TestApiService testApiService;
@PostMapping(value = "/v1/user/role/")
public CommonResponse<Object> userRole(@RequestBody UserRoleParam param) {