我正在开发一个cron,因为我正在使用Web客户端将发布请求发送到rest api。我不想让嵌入式服务器保持打开状态,因为cron需要在几秒钟内完成其任务。但是当我不通过以下方式使用服务器时:
spring.main.web-application-type=none
它显示错误,Connection prematurely closed BEFORE response; nested exception is reactor.netty.http.client.PrematureCloseException: Connection prematurely closed BEFORE response
因为它需要服务器工作,响应后我该怎么做才能停止服务器。
我试过了
server.shutdown=graceful
spring.lifecycle.timeout-per-shutdown-phase=20s
但它什么也没做(我正在使用intellij ide)
更新:我试过了
SpringApplication.exit(context, (ExitCodeGenerator) () -> 0);
但是得到 Caused by: java.lang.IllegalStateException: org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@37c7595 has been closed already
这将确保正确启动SpringBoot应用程序,并将资源释放回操作系统,
@Autowired
private ApplicationContext context;
------------------
------------------
int exitCode = SpringApplication.exit(context, (ExitCodeGenerator) () -> 0);
System.exit(exitCode);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句