服务名不要用eureka_client
,而应该是eureka-client
,不然在使用feign调用其他服务的接口时,启动报错,报错信息为:
java.lang.IllegalStateException: Service id not legal hostname (eureka_client)
在feign中使用熔断器Hystrix时,一开始我是这样写的,将通用路径“/common”放在类上,启动报错,错误信息为:
Caused by: java.lang.IllegalStateException: Ambiguous mapping.
@FeignClient(name = "eureka-client", fallback = HelloServiceFallback.class)
@Component
@RequestMapping("/common")
public interface CommonInterface {
@RequestMapping(value = "/getAyList", method = RequestMethod.GET)
JsonResult getAyList(@RequestParam(value = "id", defaultValue = "0", required = false) String id);
}
原因是控制层同一请求映射到两个方法,虽然我检查了一下没有发现相同的RequestMapping,但依旧报错,于是将“/common”放在方法上,就启动成功了。
@FeignClient(name = "eureka-client", fallback = HelloServiceFallback.class)
@Component
public interface CommonInterface {
@RequestMapping(value = "/common/getAyList", method = RequestMethod.GET)
JsonResult getAyList(@RequestParam(value = "id", defaultValue = "0", required = false) String id);
}