1.添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.0.RELEASE</version>
</dependency>
2.在启动类上添加注释:@EnableFeignClients
3.使用
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import java.util.Map;
@FeignClient(name = "fengqiuClient", url = "http://127.0.0.1:7653/api/")
@RestController
public interface FengqiuController {
@PostMapping(value = "/test", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,
consumes = "application/json;charset=UTF-8")
String lampblackDataPush(@RequestBody Map param);
}
注:@FeignClient中name参数,一个项目中不可重复,url即发送请求的地址。