package com.kwan.springcloud.service; import com.kwan.springcloud.response.Result; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; @Slf4j @Service public class FeignService { /** * http直接访问 */ private static final String GOODS_URL = "http://localhost:9100/kwanGoodsInfo/"; /** * eureka访问 */ private static final String GOODS_URL_2 = "http://goods-service/kwanGoodsInfo/"; @Autowired RestTemplate restTemplate; // @HystrixCommand(fallbackMethod = "addServiceFallback") public Result addService(String id) { //调用远程的controller return restTemplate.getForEntity(GOODS_URL_2 + id, Result.class).getBody(); } public Result addServiceFallback(String id) { log.info("失败id={}", id); return Result.error("ribbon方式请求 服务不可用 请求失败"); } }