3.构建feign模块,并创建接口org.springframework.cloud spring-cloud-starter-openfeign 2.2.7.RELEASE
@FeignClient(value = "leadnews-wemedia")//服务调用者
public interface IWemediaClient {
@GetMapping("/api/v1/channel/list")
public ResponseResult channel();
}
4.在leadnews-wemedia模块feign包下,创建一个实现类来实现远程接口,然后再对业务进行一个实现
import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.wemedia.service.WmChannelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class WemediaClient implements IWemediaClient {
@Autowired
private WmChannelService wmChannelService;
@GetMapping("/api/v1/channel/list")
@Override
public ResponseResult channel() {
return wmChannelService.findAllChannel();
}
}
在leadnews-wemedia模块下也导入feign客户端依赖
org.springframework.cloud spring-cloud-starter-openfeign 2.2.7.RELEASE
并在启动类上添加注解@EnableFeignClients(basePackages = “com.wcl.apis”),basePackages对应的是feign模块下接口的路径
@Autowired
private IWemediaClient iWemediaClient;
@Test
public void test(){
ResponseResult channel = iWemediaClient.chanwnel();
}
注:不同的模块业务下都可以进行一个远程调用,但一定要导入feign客户端的依赖和启动类添加注解
@EnableFeignClients(basePackages = “com.wcl.apis”)
org.springframework.cloud spring-cloud-starter-openfeign 2.2.7.RELEASE



