title: Schedule a task with Cron which allows dynamic update
body: <p>I use sprint boot 1.3, spring 4.2</p>
  
  <p>In this class</p>
  
  <pre><code>@Service
  public class PaymentServiceImpl implements PaymentService {
      ....
      @Transactional
      @Override
      public void processPayment() {
          List&lt;Payment&gt; payments = paymentRepository.findDuePayment();
          processCreditCardPayment(payments);
      }
  }
  </code></pre>
  
  <p>I would like to call processPayment every x moment.</p>
  
  <p>This x moment is set in a database.
  The user can modify it.</p>
  
  <p>So i think i can't use anotation.</p>
  
  <p>I started to this this</p>
  
  <pre><code>@EntityScan(basePackageClasses = {MyApp.class,     Jsr310JpaConverters.class})
  @SpringBootApplication
  @EnableCaching
  @EnableScheduling
  public class MyApp {
  
      @Autowired
      private DefaultConfigService defaultConfigService;
  
      public static void main(String[] args) {
          SpringApplication.run(MyApp.class, args);
      }
  
      @Bean
      public TaskScheduler poolScheduler() {
          SimpleAsyncTaskExecutor taskScheduler = new SimpleAsyncTaskExecutor();
  
          DefaultConfigDto defaultConfigDto = defaultConfigService.getByFieldName("payment-cron-task");
          String cronTabExpression = "0 0 4 * * ?";
          if (defaultConfigDto != null &amp;&amp; !defaultConfigDto.getFieldValue().isEmpty()) {
              cronTabExpression = "0 0 4 * * ?";
          }
  
          appContext.getBean("scheduler");
  
          taskScheduler.schedule(task, new CronTrigger(cronTabExpression));
          return scheduler;
      }
  </code></pre>
  
  <p>Maybe it's not the good way.</p>
  
  <p>Any suggestion?</p>
  
  <p>Don't know if to get my context if i need to create a property like</p>
  
  <pre><code>@Autowired
  ConfigurableApplicationContext context;
  </code></pre>
  
  <p>and after in the main</p>
  
  <pre><code>public static void main(String[] args) {
          context = SpringApplication.run(MyApp.class, args);
  }
  </code></pre>