1.httpclient
2.okhttp
3.feign
安装Gradle包
compile 'org.springframework.cloud:spring-cloud-starter-openfeign:2.0.2.RELEASE'
代码示例
@SpringBootApplication
@EnableFeignClients
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
@Service
@FeignClient(name = "httpService", url = "${url}")
public interface IHttpService {
@RequestMapping(value = "test/register", method = RequestMethod.POST, headers = "Accept=application/json", produces = "application/json;charset=UTF-8")
String add(@RequestBody RequestTestBody body);
@RequestMapping(value = "register/{name}", method = RequestMethod.PUT)
String update(@PathVariable("name") String name, @RequestBody RegisterDto body);
@RequestMapping(value = "test123/{name}", method = RequestMethod.DELETE)
String delete(@PathVariable("name") String name);
}