Springcloud使用feign客户端调用服务接口
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-openfeign</artifactId> </dependency>
在启动类添加注解开启feign
@EnableFeignClients
定义一个接口 接口上注解的值是要调用的服务在注册中心的名称,@Requestmapping的值是要调用服务中的接口的映射
1.@FeignClient(name="eureka-member") public interface FeignToMember { @RequestMapping("getMember") public String getMember(); }
直接调用
@Autowired private FeignToMember feignToMember; @RequestMapping("feignToMember") public String feignToMember() { return feignToMember.getMember(); }