title: Spring-Boot one @Scheduled task using multiple cron expressions from yaml file
body: <p>I like to have an implementation of one <code>@Scheduled</code> job using different configuration properties of <code>.yml</code>file. </p>
  
  <p>Means in my yaml file I describe the <code>cron expression</code> as a list:</p>
  
  <pre><code>job:
    schedules:
    - 10 * * * * *
    - 20 * * * * *
  </code></pre>
  
  <p>I read those values out using Configuration and created a <code>@Bean</code> named <code>scheduled</code>:</p>
  
  <pre><code>@Configuration
  @ConfigurationProperties(prefix="job", locations = "classpath:cronjob.yml")
  public class CronConfig {
  
      private List&lt;String&gt; schedules;
  
      @Bean
      public List&lt;String&gt; schedules() {
          return this.schedules;
      }
  
      public List&lt;String&gt; getSchedules() {
          return schedules;
      }
  
      public void setSchedules(List&lt;String&gt; schedules) {
          this.schedules = schedules;
      }
  }
  </code></pre>
  
  <p>In my Job class I want to start the execution of one method but for both of the schedules in my configuration.</p>
  
  <pre><code> @Scheduled(cron = "#{@schedules}")
   public String execute() {
       System.out.println(converterService.test());
       return "success";
   }
  </code></pre>
  
  <p>With this solution the application creates an error: (more or less clear)</p>
  
  <pre><code>Encountered invalid @Scheduled method 'execute': Cron expression must consist of 6 fields (found 12 in "[10 * * * * *, 20 * * * * *]")
  </code></pre>
  
  <p><strong>Is there a way to configure the same scheduled job method with multiple declarations of cron expressions?</strong></p>
  
  <hr>
  
  <p><strong>EDIT 1</strong></p>
  
  <p>After some try I just used a second annotation on the executer method. </p>
  
  <pre><code>@Scheduled(cron = "#{@schedules[0]}")
  @Scheduled(cron = "#{@schedules[1]}")
  public String execute() {
      System.out.println(converterService.test());
      return "success";
  }
  </code></pre>
  
  <p>This solution works but is not really dynamic. Is there also a way to make this dynamic?</p>