我目前正在检查如何在我的一个项目中使用 Feign 作为声明式 REST 客户端。
以下是 Feign 客户端
@FeignClient(name = "SEARCHCABMS",configuration = AppFeignConfiguration.class)
public interface SearchCabMsClient {
@RequestMapping(value = "api/searchcab/locationcabtimedetail/search/getCabForLocationAfterTimeSlot", method = RequestMethod.GET)
String searchCabDetails(@PathVariable("fromDate") String fromDate,
@PathVariable("locationId") long locationId,
@PathVariable("isdeleted") byte isdeleted,
@PathVariable("hourforbooking")int hourforbooking);
}
此接口在一项服务中自动装配
@Autowired
SearchCabMsClient restService;
将 EnableFeignClients 添加到 SpringBootApplication
@EnableFeignClients(basePackages = {"com.gp.cabbooking.services.feign"})
pom.xml 中的依赖项、父项等
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
</parent>
依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-ribbon</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-feign</artifactId>
</dependency>
在为我的 feign 客户端调试 spring create 代理时,我可以看到我尝试在功能区的帮助下调用此服务,它工作正常,但是当我在我的 feign 客户端中执行方法定义时。我得到feign.FeignException: status 404 reading
feign.FeignException: status 404 reading SearchCabMsClient#searchCabDetails(String,long,byte,int)
at feign.FeignException.errorStatus(FeignException.java:62) ~[feign-core-8.16.2.jar:8.16.2]
at feign.codec.ErrorDecoder$Default.decode(ErrorDecoder.java:91) ~[feign-core-8.16.2.jar:8.16.2]
at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:134) ~[feign-core-8.16.2.jar:8.16.2]
at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:76) ~[feign-core-8.16.2.jar:8.16.2]
at feign.hystrix.HystrixInvocationHandler$1.run(HystrixInvocationHandler.java:97) ~[feign-hystrix-8.16.2.jar:8.16.2]
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:293) ~[hystrix-core-1.5.3.jar:1.5.3]
at com.netflix.hystrix.HystrixCommand$1.call(HystrixCommand.java:289) ~[hystrix-core-1.5.3.jar:1.5.3]
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:46) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:30) ~[rxjava-1.1.5.jar:1.1.5]
at rx.Observable.unsafeSubscribe(Observable.java:8460) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:51) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.operators.OnSubscribeDefer.call(OnSubscribeDefer.java:35) ~[rxjava-1.1.5.jar:1.1.5]
at rx.internal.operators.OnSubscribeLift.call(OnSubscribeLift.java:50) ~[rxjava-1.1.5.jar:1.1.5]