Feign是Netflix开发的声明式、模板化的HTTP客户端, Feign可以帮助我们更快捷、优雅地调用HTTP API。
@FeignClient(name = "app-cjbdi-member")
public interface MemberServiceFeign {
@RequestMapping(value = "/{id}", method = RequestMethod.GET)
public User findById(@PathVariable("id") Long id);
}
注:这里建议提取出来做成公共的,进行继承式调用。
@EnableDiscoveryClient //让注册中心能够发现这个服务
@EnableFeignClients(basePackages = {"com.cjbdi.order.feign"})//fegin客户端
@RestController
public class MovieController {
@Autowired
private MemberServiceFeign memberServiceFeign;
@GetMapping("/user/{id}")
public User findById(@PathVariable Long id) {
return this.memberServiceFeign.findById(id);
}
}