如何防止Spring Boot守护程序/服务器应用程序立即关闭/关闭? [英] How to prevent Spring Boot daemon/server application from closing/shutting down immediately?
问题描述
My 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依赖项,要么添加camel.springboot.main-run- controller = true到您的application.properties或application.yml文件。
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.
您也需要以下依赖项:
< dependency>
< groupId> org.apache.camel< / groupId>
< artifactId> camel-spring-boot-starter< / artifactId>
< version> 2.17.0< / version>
< / dependency>
明确替换< version> 2.17.0< / version>
或使用驼峰BOM导入依赖关系管理信息以保持一致性。
Clearly replace <version>2.17.0</version>
or use the camel BOM to import dependency-management information for consistency.
这篇关于如何防止Spring Boot守护程序/服务器应用程序立即关闭/关闭?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!