我在我的本地tomcat上运行了Spring Cloud。我正在使用feign客户端来调用Hysterix命令中包含的远程服务,如下所示直接和其他异步。
@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();
}
};
}
当我调用getEmployeesAsync()时.get() 我得到了以下异常
java.lang.UnsupportedOperationException:AsyncResult只是一个刺,不能用作Future的完整实现
类似于以下问题: -
[https://github.com/Netflix/Hystrix/issues/1179][1]
根据文档,解决方案是配置HystrixCommandAspect类,我做如下: -
@Configuration
@EnableAspectJAutoProxy
public class HystrixConfiguration {
@Bean
public HystrixCommandAspect hystrixAspect() {
return new HystrixCommandAspect();
}
}
但我仍然得到同样的例外。看来我错过了一些配置。 注意: - 我的同步方法工作正常。
答案 0 :(得分:1)
您可以尝试在另一个类中调用getEmployeesAsync
,该类为phoneNum.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFoucs) {
if(!hasFoucs){
Phone = phoneNum.getText().toString();
if (!Phone.matches("^\\d{3}-\\d{3}-\\d{4}$/")){
phoneNum.setBackgroundColor(Color.parseColor("#FFBABA"));
Toast.makeText(ctx,"Phone Syntax incorrect",Toast.LENGTH_LONG).show();
flag_phone = 0;
}
else {
phoneNum.setBackgroundColor(Color.WHITE);
flag_phone =1;
}
} else {
phoneNum.setBackgroundColor(Color.WHITE);
}
}
});
注入了类的实例。我也有这个例外。然后我就这样成功了。