一.导入依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-openfeign</artifactId>
<scope>provided </scope>
</dependency>
二.编写远程调用接口
- 注意:
*远程调用接口上加@FeignClient(“service-user”)注解,其中参数为被调用者在nacos注册中心的服务名.
远程调用接口中方法必须与被访问的接口方法完全一致(请求方式,完整请求路径,方法等完全一致)
@FeignClient("service-user")
public interface PatientFeignClient {
@GetMapping("/api/userInfo/patient/remote/{pid}")
public Patient getRemotePatientInfo(@PathVariable("pid") Long pid);
}
三.在主启动类上加@EnableFeignClients(basePackages = {“com.atguigu”})(扫描编写的远程调用所在的包)
四.在需要使用的地方注入接口电泳方法
@Autowired
private PatientFeignClient patientFeignClient;