我在服务层的spring引导应用程序中使用Hystrix (version Camden.SR7 of spring-cloud-dependencies),没有后备方法。服务的一个方法如下所示:
@HystrixCommand(commandKey = "prefs",
commandProperties = { @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")})
@Override
public void savePrefs(PrefsRequestParams requestParams) throws Exception {
...
}如果该方法执行时间超过2秒,Hystrix将抛出java.util.concurrent.TimeoutException: null,REST响应如下所示:
{
"timestamp": 1509452672714,
"status": 500,
"error": "Internal Server Error",
"exception": "java.util.concurrent.TimeoutException",
"message": "No message available",
"path": "/prefs"
}对于这样的响应,还不清楚是从哪种方法异常引发的。如果我将spring-cloud-dependencies版本更改为Brixton.SR5 (以前的版本),它将返回明确的响应:
{
"timestamp": 1509452426819,
"status": 500,
"error": "Internal Server Error",
"exception": "com.netflix.hystrix.exception.HystrixRuntimeException",
"message": "prefs timed-out and fallback failed.",
"path": "/prefs"
}因此,新版本的Hystrix (实际上是spring依赖关系的新版本)不会抛出。这是一个错误,还是应该以另一种方式配置Hystrix以接收清楚的消息错误?
我使用以下maven依赖项:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix</artifactId>
<version>1.2.7.RELEASE</version>
</dependency>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Camden.SR7</version>
<type>pom</type>
<scope>import</scope>
</dependency>
...从maven依赖树中可以看出,它使用com.netflix.hystrix:hystrix-core:jar:1.5.6:compile表示spring-cloud-dependencies版本Camden.SR7,以及版本Brixton.SR5 - com.netflix.hystrix:hystrix-core:jar:1.5.3:compile。
发布于 2017-10-31 13:52:53
更新到Javanica 1.5.12可以解决这个问题。
在1.5.7中,还有一个选项可以强制抛出所有未被忽略的异常的HystrixRuntimeException:
@HystrixCommand(raiseHystrixExceptions = {HystrixException.RUNTIME_EXCEPTION})
@Override
public void savePrefs(PrefsRequestParams requestParams) throws Exception {
...
}https://stackoverflow.com/questions/47036396
复制相似问题