我有一个后端spring-boot应用程序和一个前端React \ Redux应用程序。在生产中,这些应用程序部署在其他VM上。为了模仿生产,我在React dev env中使用了一个代理(端口号与后端号不同)。
“proxy”: http://localhost:8081
通过邮递员获得结果时,通过React应用程序获得以下错误消息:
•在后端控制台中:
java.lang.IllegalStateException: Calling [asyncError()] is not valid for a request with Async state [MUST_DISPATCH]
at org.apache.coyote.AsyncStateMachine.asyncError(AsyncStateMachine.java:440) ~[tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.coyote.AbstractProcessor.action(AbstractProcessor.java:513) [tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.coyote.Request.action(Request.java:430) ~[tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.catalina.core.AsyncContextImpl.setErrorState(AsyncContextImpl.java:401) ~[tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.catalina.connector.CoyoteAdapter.asyncDispatch(CoyoteAdapter.java:239) ~[tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.coyote.AbstractProcessor.dispatch(AbstractProcessor.java:242) [tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:53) [tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:861) [tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1579) [tomcat-embed-core-9.0.27.jar:9.0.27]
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) [tomcat-embed-core-9.0.27.jar:9.0.27]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.27.jar:9.0.27]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]
•在浏览器中:
Failed to load resource: net:: ERR_EMPTY_RESPONSE
@GetMapping("/rb-test")
public ResponseEntity<ResponseBodyEmitter> handle() {
ResponseBodyEmitter emitter = new ResponseBodyEmitter();
service.findAllComm().thenAccept(list -> {
try {
emitter.send(list);
emitter.complete();
} catch (IOException e) {
emitter.completeWithError(e);
}
});
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
return new ResponseEntity(headers ,emitter, HttpStatus.OK);
}
@Async
public CompletableFuture<List<TchDev>> findAllComm() {
return CompletableFuture.supplyAsync(() -> repository.findAllCommxxx());
}
从我所做的研究来看,这显然是Tomcat的缺陷。有什么解决方法吗?
谢谢