spring cloud openfeign
Feign是一个声明性的Web服务客户端。使用Feign,在Application启动类上加入 @EnableFeignClients 这个注解,启用Feign。Feign支持可插拔编码器和解码器。
@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class WebsocketApplication {
public static void main(String[] args) {
SpringApplication.run(WebsocketApplication.class, args);
}
}
依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
过期的依赖,现在使用如下的版本
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>
@FeignClient
@FeignClient注解方法,name是服务名,path是服务路径前缀。
对于Get请求,请求参数为一个引用对象的时候,可以使用 @SpringQueryMap 注解;对于Post注解,需要使用@RequestBody注解