从请求范围的线程中,CompletableFuture
s 必须由在执行程序中运行的任务完成。MessageService
提供的供应商使用会话范围内的特定领域服务。该服务由 Guice 注入。
public class MessageProcessingPage {
private MessageService messageService;
@Inject
public MessagProcessingPage (MessageService messageService) {
this.messageService = messageService;
}
// Called by request scoped thread.
public void onProcessMessagesButton () {
ExecutorService executorService = Executors.newFixedThreadPool(3);
CompletableFuture.supplyAsync(
// Called from a thread from the threadpool.
() -> {return messageService.retrieveMessageMetadataSet(x, y);}
, executorService);
...
}
...
}
有MessageService
一个(会话范围)MessageRestClient
被注入。
@SessionScoped
public class MessageService {
private MessageRestClient messageRestClient;
@Inject
public MessageRestClient (MessageRestClient messageRestClient) {
this.messageRestClient = messageRestClient;
}
public MessageMetaDataSet retrieveMessageMetadataSet(x, y) {
List<MessageMetaData> listOfMetaData = messageRestClient.retrieve(x, y, z);
...
}
...
}
@SessionScoped
public class MessageRestClient {
...
}
Guice 在尝试注入MessageRestClient
.
java.util.concurrent.CompletionException: com.google.inject.ProvisionException: Unable to provision, see the following errors:
1) Error in custom provider, com.google.inject.OutOfScopeException: Cannot access scoped [MessageRestClient]. Either we are not currently inside an HTTP Servlet request, or you may have forgotten to apply com.google.inject.servlet.GuiceFilter as a servlet filter for this request.
ServletScopes
我在:中读到了一个方法,public static <T> Callable<T> transferRequest(Callable<T> callable)
但我看不到使用它的方法,因为没有 Callables 可以发挥作用。你能帮我解决一下吗?