I have following api returning Flux of String
我有以下返回字符串通量的接口
@GetMapping(value = "/api/getStrListFlux",produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> getListOfStr0() {
return Flux.just("Str-1", "Str-2", "Str-3", "Str-4", "Str-5")
.log().delayElements(Duration.ofSeconds(1));
}
Whenever I stop the Springboot Application while above method is yet to finish producing all the elements, following exception is thrown
每当我在上述方法尚未完成所有元素的生成时停止SpringBoot应用程序时,都会抛出以下异常
2023-09-11T09:05:28.695+08:00 INFO 2776 --- [nio-8080-exec-1] reactor.Flux.OnErrorReturn.1 : onSubscribe(FluxOnErrorReturn.ReturnSubscriber)
2023-09-11T09:05:28.698+08:00 INFO 2776 --- [nio-8080-exec-1] reactor.Flux.OnErrorReturn.1 : request(1)
2023-09-11T09:05:28.698+08:00 INFO 2776 --- [nio-8080-exec-1] reactor.Flux.OnErrorReturn.1 : onNext(Str-1)
2023-09-11T09:05:29.704+08:00 INFO 2776 --- [ parallel-1] reactor.Flux.OnErrorReturn.1 : request(1)
2023-09-11T09:05:29.704+08:00 INFO 2776 --- [ parallel-1] reactor.Flux.OnErrorReturn.1 : onNext(Str-2)
2023-09-11T09:05:30.709+08:00 INFO 2776 --- [ parallel-2] reactor.Flux.OnErrorReturn.1 : request(1)
2023-09-11T09:05:30.709+08:00 INFO 2776 --- [ parallel-2] reactor.Flux.OnErrorReturn.1 : onNext(Str-3)
2023-09-11T09:05:31.711+08:00 INFO 2776 --- [ parallel-3] reactor.Flux.OnErrorReturn.1 : request(1)
2023-09-11T09:05:31.711+08:00 INFO 2776 --- [ parallel-3] reactor.Flux.OnErrorReturn.1 : onNext(Str-4)
2023-09-11T09:05:32.714+08:00 INFO 2776 --- [ parallel-4] reactor.Flux.OnErrorReturn.1 : request(1)
2023-09-11T09:05:32.715+08:00 INFO 2776 --- [ parallel-4] reactor.Flux.OnErrorReturn.1 : onNext(Str-5)
2023-09-11T09:05:32.718+08:00 INFO 2776 --- [ parallel-4] reactor.Flux.OnErrorReturn.1 : onComplete()
Exception in thread "task-6" java.lang.UnsupportedOperationException: The dispatcher returned from the ServletContext does not support asynchronous dispatching
at org.apache.catalina.core.AsyncContextImpl.dispatch(AsyncContextImpl.java:196)
at org.apache.catalina.core.AsyncContextImpl.dispatch(AsyncContextImpl.java:174)
at org.apache.catalina.core.AsyncContextImpl.dispatch(AsyncContextImpl.java:168)
at org.springframework.web.context.request.async.StandardServletAsyncWebRequest.dispatch(StandardServletAsyncWebRequest.java:135)
at org.springframework.web.context.request.async.WebAsyncManager.setConcurrentResultAndDispatch(WebAsyncManager.java:405)
at org.springframework.web.context.request.async.WebAsyncManager.lambda$startDeferredResultProcessing$8(WebAsyncManager.java:473)
at org.springframework.web.context.request.async.DeferredResult.setResultInternal(DeferredResult.java:272)
at org.springframework.web.context.request.async.DeferredResult.setResult(DeferredResult.java:243)
at org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitterReturnValueHandler$HttpMessageConvertingHandler.complete(ResponseBodyEmitterReturnValueHandler.java:223)
at org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitter.complete(ResponseBodyEmitter.java:235)
at org.springframework.web.servlet.mvc.method.annotation.ReactiveTypeHandler$AbstractEmitterSubscriber.run(ReactiveTypeHandler.java:355)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1144)
at java. Base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:642)
at java.base/java.lang.Thread.run(Thread.java:1623)
Could not able to find any help. Please explain what is the cause and remedy for this..
找不到任何帮助。请解释一下造成这种情况的原因和补救措施。
I expect that SpringBoot application shutdowns gracefully and there is no error while doing so.
我希望SpringBoot应用程序能够正常关闭,并且不会出现任何错误。
更多回答
in order for it to shutdown gracefully u need to set this property server.shutdown=graceful
. if you dont have it, try with it again
为了让它正常关闭,您需要设置此属性server.Shutdown=graceful。如果你没有,再试一次
it worked .. thanks
它成功了..。谢谢
i ll post the solution as an answer. can you please mark it as right so that the thread gets solved? thanks
我会将解决方案作为答案发布。你能把它标记为正确吗,这样线就可以解决了吗?谢谢
优秀答案推荐
in order for it to shutdown gracefully u need to set this property: server.shutdown=graceful
为了让它正常关闭,您需要设置此属性:server.Shutdown=graceful
更多回答
我是一名优秀的程序员,十分优秀!