【发布时间】:2018-04-05 09:47:31
【问题描述】:
我有一个返回 ResponseEntity<List<Attachment>> 的服务方法,它的 hystrix fallback 方法也必须返回 ResponseEntity<List<Attachment>>。
问题是我需要返回一个字符串消息来向用户澄清错误,而不是返回一个新的Arraylist<>()
- 这是我的方法
@Override
@HystrixCommand(fallbackMethod = "getAttachmentsFallback")
public ResponseEntity<List<AttachmentDto>> getAttachments(IAttachable entity) {
List<AttachmentDto> attachments = client.getAttachments(entity.getAttachableId(), entity.getClassName(),
entity.getAppName());
return new ResponseEntity<List<AttachmentDto>>(attachments, HttpStatus.OK);
}
这就是它的后备方式
public ResponseEntity<List<AttachmentDto>> getAttachmentsFallback(IAttachable entity, Throwable e) {
//I need to return a String instead of the new Arraylist<AttachmentDto>()
return new ResponseEntity<List<AttachmentDto>>(new ArrayList<AttachmentDto>(), HttpStatus.INTERNAL_SERVER_ERROR);
}
【问题讨论】:
标签: java spring hystrix fallback