简单使用Feign
一:如何使用feign
1.消费者的启动类加上@EnableFeignClients注解
2.导入依赖
<!--Spring Cloud OpenFeign Starter -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<version>2.1.2.RELEASE</version>
</dependency>
3.创建feign接口
@Component
@RequestMapping("/miniprogram/message")
@FeignClient("${sc.app-name}-sc-miniprogram")
public interface MiniprogramClient {
@PostMapping("/miniprogram/send")
public Result sendMessageMiniprogram(@RequestBody JSONObject jsonData);
}
@FeignClient(“${sc.app-name}-sc-miniprogram”) 注解为生产者服务名称
@RequestMapping(“/miniprogram/message”)
@Post