我有一个返回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);
}
发布于 2017-10-27 08:20:06
我是通过不使用args而不是使用ResponseEntity
来工作的
谢谢各位
发布于 2017-10-26 17:18:21
只需使用:
ResponseEntity<Object>
这适用于任何类型。因为Object是在java.lang中定义的最高级类。
而不是:
ResponseEntity<List<AttachmentDto>>
https://stackoverflow.com/questions/46913185
复制相似问题