Histerix Javanica AsyncResult Future.get引发异常
我在本地的tomcat上安装了一个Spring云。我正在使用假客户机调用一个远程服务,该服务封装在一个direct和另一个async命令中,如下所示Histerix Javanica AsyncResult Future.get引发异常,java,hystrix,spring-cloud-netflix,Java,Hystrix,Spring Cloud Netflix,我在本地的tomcat上安装了一个Spring云。我正在使用假客户机调用一个远程服务,该服务封装在一个direct和另一个async命令中,如下所示 @HystrixCommand(fallbackMethod = "fallBackEmployeeCall") public List<EmployeeBean> getEmployees() { //Call through Feign Client return empInterface.g
@HystrixCommand(fallbackMethod = "fallBackEmployeeCall")
public List<EmployeeBean> getEmployees() {
//Call through Feign Client
return empInterface.getEmployees();
}
//Async Version
@HystrixCommand(fallbackMethod = "fallBackEmployeeCall")
public Future<List<EmployeeBean>> getEmployeesAsync() {
return new AsyncResult<List<EmployeeBean>>() {
@Override
public List<EmployeeBean> invoke() {
return empInterface.getEmployees();
}
};
}
根据文档,解决方案是配置HYSTRIxCommandSpect类,我的操作如下:-
@Configuration
@EnableAspectJAutoProxy
public class HystrixConfiguration {
@Bean
public HystrixCommandAspect hystrixAspect() {
return new HystrixCommandAspect();
}
}
但我还是得到了同样的例外。似乎我缺少一些配置。
注意:-我的同步方法工作正常。您可以尝试在另一个类中调用
getEmployeesAsync
,该类将getEmployeesAsync
注入该类的实例。我也有这个例外。然后我就这样成功地完成了。您可以发布客户端代码,在哪里测试调用?在另一个类中调用它会有什么不同?你能详细说明一下吗?
@Configuration
@EnableAspectJAutoProxy
public class HystrixConfiguration {
@Bean
public HystrixCommandAspect hystrixAspect() {
return new HystrixCommandAspect();
}
}