【发布时间】:2017-01-01 11:11:20
【问题描述】:
我在我的 Spring Boot 应用程序中使用 hystrix,但是当我访问 /hystrix-stream 页面时没有数据。它只显示“ping:”。 在我的 pom.xml 我有以下内容:
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</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-hystrix</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-hystrix-dashboard</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
我已启用 Hystrix 和 HystrixDashboard。此外,我在我的应用程序中使用功能区。 HystrixCommand 如下所示:
@HystrixCommand(fallbackMethod = "defaultFallback")
public byte[] doGet() {
return this.restTemplate.getForObject("http://myInstance/api/v3/ressource",byte[].class);
}
public byte[] defaultFallback() {
System.out.println("Now doing fallback!");
return null;
}
当我关闭 myInstance 时,没有调用回退,功能区只显示此失败:
There was an unexpected error (type=Internal Server Error, status=500).
I/O error on POST request for "http:/myInstance/api/v3/ressource": Connection
refused; nested exception is java.net.ConnectException: Connection refused
【问题讨论】:
-
你从哪里调用 doGet 方法?来自同一个班级还是来自某个外部班级?
-
你有完整的堆栈跟踪吗?
标签: java spring spring-cloud hystrix spring-cloud-netflix