My Spring Boot application is not a web server, but it\'s a server using custom protocol (using Camel in this case).
But Spring Boot immediately stops (gracefully) a
Spring Boot leaves the task of running the application to the protocol around which the application is implemented. See, for example, this guide:
Also required are some housekeeping objects like a
CountDownLatch
to keep the main thread alive...
So the way of running a Camel service, for example, would to be to run Camel as a standalone application from your main Spring Boot application class.
As of Apache Camel 2.17 there is a cleaner answer. To quote http://camel.apache.org/spring-boot.html:
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.
You will want the following dependency too:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.17.0</version>
</dependency>
Clearly replace <version>2.17.0</version>
or use the camel BOM to import dependency-management information for consistency.
All threads are completed, the program will close automatically.
So, register an empty task with @Scheduled
will create a loop thread to prevent shutdown.