如何关闭Spring Boot嵌入式服务器

阿西姆

我正在开发一个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

伊斯蒂亚克·侯赛因(Istiaque Hossain)

这将确保正确启动SpringBoot应用程序,并将资源释放回操作系统,

@Autowired
private ApplicationContext context;

------------------
------------------
int exitCode = SpringApplication.exit(context, (ExitCodeGenerator) () -> 0);
System.exit(exitCode);

原始问题链接

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何防止嵌入式网状服务器从弹簧引导起动webflux开始?

如何创建Ktor嵌入式服务器的.jar(创建可执行文件)

Spring Boot为嵌入式服务器配置自定义jsessionid

如何创建嵌入式WebSocket服务器Jetty 9?

嵌入式Tomcat强化-如何在Spring Boot中更改/覆盖广告服务器信息?

Spring Boot是否以战争方式部署在外部服务器上时使用外部服务器还是嵌入式服务器?

在大型企业中运行Spring Boot Microservices是否需要嵌入式Tomcat服务器的许可证?

在Linux的嵌入式Tomcat服务器中运行Spring Boot应用程序

使用Grizzly的嵌入式Java服务器:如何启用http2

如何将简单的Spring Boot(带有Gradle构建系统)部署到Apache Tomcat(真实服务器,而不是嵌入式服务器)?

具有不同嵌入式服务器的Spring Boot WAR大小

如何将嵌入式PostgreSQL服务器Java组件用作单独的服务?

如何在Spark嵌入式Web服务器中启用HTTP / 2

如何找到嵌入式Redis端口并杀死嵌入式Redis服务器

Spring Boot服务器无法启动嵌入式Tomcat服务器

如何在Undertow嵌入式服务器中登录文件?

使用嵌入式码头,如何将ServerConnector链接到服务器?

如何配置嵌入式码头服务器记录所有请求?

如何在嵌入式板上检查/调整SSH服务器

SolrJ嵌入式服务器Spring Config不再起作用

使用Spring Boot在嵌入式Tomcat服务器上部署资源

Jetty嵌入式服务器和Spring Security集成

spring boot中嵌入式solr服务器的类路径是什么?

有没有办法用spring boot 1.x选择嵌入式服务器类型

如何与 Openmodelica 嵌入式 opc-ua 服务器交互

无法启动 bean 'webServerStartStop';无法启动嵌入式 Tomcat 服务器 - spring-boot-starter-web

我将如何在 Openshift 上实现嵌入式 SFTP 服务器

请求参数被记录在带有 Spring Boot 应用程序的嵌入式码头服务器的访问日志中

如何连接到 ActiveMQ Artemis 嵌入式服务器?