3、在调用端的启动类添加注解 @EnableFeignClients 4、创建包和接口 创建client包 @FeignClient注解用于指定从哪个服务中调用功能 ,名称与被调用的服务名保持一致。 @GetMapping注解用于对被调用的微服务进行地址映射。 @PathVariable注解一定要指定参数名称,否则出错 @Component注解防止,在其他位置注入VodClient时idea报错 package com.atguigu.eduservice.feign;import com.atguigu.common.R;import org.springframework.cloud.openfeign.FeignClient;import org.springframework.stereotype.Component;import org.springframework.web.bind.annotation.DeleteMapping;import org.springframework.web.bind.annotation.PathVariable;/** * @Author csddp * @Date 2021/1/30 15:43 * @Description 服务调用 **/@FeignClient(value = "service-vod")@Componentpublic interface VodFeign { @DeleteMapping("/eduvod/video/removeAlyVideo/{id}") public R removeAlyVideo(@PathVariable("id") String id);}
5、调用微服务 在调用端的VideoServiceImpl中调用client中的方法 注入VodFeign 然后调用方法 @Autowiredprivate VodFeign vodFeign; vodFeign.removeAlyVideo(id); 6、测试 启动相关微服务 测试删除课时的功能