feign入门案例

1.引入依赖

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>

2.配置调用接口

@FeignClient(name="service-product")
public interface ProductFeignClient {

    /*
    *配置需要调用的微服务接口
    * */
    @RequestMapping(value = "/product/{id}",method = RequestMethod.GET)
    public Product findById(@PathVariable("id") Long id);

}

3.激活feign @EnableFeignClients

@SpringBootApplication
@EntityScan("com.yxkj.eneity")
@EnableFeignClients
public class OrderApplication {
    public static void main(String[] args) {
        SpringApplication.run(OrderApplication.class,args);
    }
}

4.测试调用远程微服务


    @Autowired
    private ProductFeignClient productFeignClient;

    @RequestMapping(value = "/buy/{id}",method = RequestMethod.GET)
    public Product findById(@PathVariable Long id){
        Product product = null;
        product = productFeignClient.findById(id);
        return product;
    }

feign入门案例

上一篇:线上服务器CPU彪高的调试方式


下一篇:快速简单的了解VLAN(VXLAN)和端口链路类型