title: Spring Boot - long running application for non-web app
body: <p>I have a simple Spring-Boot application that just uses the AMQP dependency (just <code>'org.springframework.boot:spring-boot-starter-amqp'</code> - e.g. no web dependencies so no app server being included in the JAR).</p>
  
  <p>All I want is for the application to run and listen to a queue and log some info to the DB whenever a message is recieved - however, as there is no application server, as soon as it starts up it just shuts down again (as there is nothing being done). Is there a best way to keep this application running whilst listening for messages?</p>
  
  <p>There is nothing surprising in the code, just the standard application config, then also a class marked with @RabbitListener</p>
  
  <pre><code>@SpringBootApplication
  class PersistenceSeriveApplication {
  
      static void main(String[] args) {
          SpringApplication.run PersistenceSeriveApplication, args
      }
  }
  
  @Configuration
  @EnableRabbit
  class QueueConfiguration {
  
      @Bean public Queue applicationPersistenceQueue( @Value( '${amqp.queues.persistence}' ) String queueName ) {
          new Queue( queueName )
      }
  }
  </code></pre>
  
  <p>(One option I considered was just spinning up a scheduled process - just a heartbeat or something, which would probably be nice for monitoring anyway - but is there any other better/standard way?)</p>