CompletableFuture.supplyAsync lambda 中缺少 return 语句

问题描述 投票:0回答:1

我有这个Java代码:

public ResponseEntity<Resources> getByTokenResource(HttpHeaders headers, String payload) {
    return invoke(headers, payload);
}

.......

@TimeLimiter(name = "getToken")
@CircuitBreaker(name = "getToken", fallbackMethod = "fallbackRequestException")
public ResponseEntity<Resources> getByTokenPayload(HttpHeaders headers, String payload) 
{
    return service.getByTokenResource(headers, payload);
}

.......

Details getRequest(HttpHeaders httpHeaders, String url) {
    try {
        ResponseEntity<Resources> response =
                secondService.getByToken(httpHeaders, url);
    } catch (Exception e) {
        ......
    }
    return ....;
}

我尝试以这种方式编辑代码以解决此问题:

@Bulkhead(name = "getToken", type = Bulkhead.Type.THREADPOOL)
@TimeLimiter(name = "getToken")
@CircuitBreaker(name = "getToken", fallbackMethod = "fallbackRequestException")
public ResponseEntity<Resources> getByTokenPayload(HttpHeaders headers, String url) {
    return CompletableFuture.supplyAsync(() -> {
        ResponseEntity<Resources> result = service.getByTokenResource(headers, url);
    }).thenApply(result -> {
        return result;
    });
}

我在这一行遇到错误

Missing return statement
}).thenApply(result -> {

你知道我该如何解决这个问题吗?

java lambda error-handling
1个回答
0
投票

要消除错误,您需要使用 join() 而不是 thenApply()。

© www.soinside.com 2019 - 2024. All rights reserved.