如何防止 Spring Boot 守护进程/服务器应用程序立即关闭/关闭? [英] How to prevent Spring Boot daemon/server application from closing/shutting down immediately?

查看:58
本文介绍了如何防止 Spring Boot 守护进程/服务器应用程序立即关闭/关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的 Spring Boot 应用程序不是 Web 服务器,而是使用自定义协议的服务器(在本例中使用 Camel).

My Spring Boot application is not a web server, but it's a server using custom protocol (using Camel in this case).

但是 Spring Boot 在启动后立即停止(优雅地).我如何防止这种情况?

But Spring Boot immediately stops (gracefully) after started. How do I prevent this?

我希望应用在 Ctrl+C 或以编程方式停止.

I'd like the app to stop if Ctrl+C or programmatically.

@CompileStatic
@Configuration
class CamelConfig {

    @Bean
    CamelContextFactoryBean camelContext() {
        final camelContextFactory = new CamelContextFactoryBean()
        camelContextFactory.id = 'camelContext'
        camelContextFactory
    }

}

推荐答案

从 Apache Camel 2.17 开始,有一个更清晰的答案.引用http://camel.apache.org/spring-boot.html:

As of Apache Camel 2.17 there is a cleaner answer. To quote http://camel.apache.org/spring-boot.html:

为了保持主线程阻塞以便 Camel 保持运行,要么包含 spring-boot-starter-web 依赖项,要么在 application.properties 或 application.yml 文件中添加camel.springboot.main-run-controller=true.

To keep the main thread blocked so that Camel stays up, either include the spring-boot-starter-web dependency, or add camel.springboot.main-run-controller=true to your application.properties or application.yml file.

您也需要以下依赖项:

<代码><依赖><groupId>org.apache.camel</groupId><artifactId>camel-spring-boot-starter</artifactId><version>2.17.0</version></依赖>

明确替换2.17.0或使用camel BOM导入依赖管理信息以保持一致性.

Clearly replace <version>2.17.0</version> or use the camel BOM to import dependency-management information for consistency.

这篇关于如何防止 Spring Boot 守护进程/服务器应用程序立即关闭/关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆