原因
由于使用feign,spring cloud默认整合了Ribbon、Hystrix。而Hystrix默认的超时时间为1s,而使用feign第一次请求在配置较差的机器上运行时,很可能请求时间超过1s而超时。
解决方案
1、设置Hystrix的超时时间,例如设置超时时间为5s
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds: 5000
2、不设置Hystrix的超时时间
hystrix.command.default.execution.timeout.enabled: false
3、禁用Hystrix
feign.hystrix.enabled: false
以上三种方式皆是在服务消费端的application.properties或application.yml文件中配制。