feign其实是针对原来的ribbon做了一层封装,使得远程调用面向接口,直接提供参数和request映射即可:
同样的,在上几篇博客的基础上,copy一份order-service模块出来,其他不变,就是删除掉RibbonServiceImpl
然后直接提供接口和相关的参数:修改RibbonService
@FeignClient(value = "USER-SERVICE") ///指命相关的微服务
public interface RibbonUserService {
// 只提供相应的接口和映射即可
@RequestMapping(value = "/v1/user",method = RequestMethod.GET)
UserInfoResp getUserInfoFeign();
}
记得在pom.xml文件中加入feign的依赖:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
</dependencies>
在启动类上加入注解:
@EnableFeignClients
修改后为:
@SpringBootApplication
@EnableDisc