优雅的http接口调用-feign。
spring-cloud-feign是spring cloud微服务之间调用封装的功能,由于feign的封装和解耦做的比较好,因此脱离spring cloud也能使用。
Spring boot项目使用feign
项目背景:spring boot 2.2.5.RELEASE
引入Maven
org.springframework.cloud
spring-cloud-starter-openfeign
2.2.5.RELEASE
启动注解
和spring cloud项目一样,同样需要在启动类上添加注解
@EnableFeignClients
Feign接口
接下来直接写feign的接口就行了,和产品spring cloud项目相比,这里的服务地址不再是服务名,而换成了具体的url
@FeignClient(url = "${ca.url}", name = "caClient")
public interface CaClient {
@PostMapping(value = "ca", headers = "TOKEN=${ca.token}")
Result ca(@RequestBody CaDto dto);
}



