title: Cron expression must consist of 6 fields(found 1 in "${cron.expression}) partially fixed but having issues with AnnotationConfigApplicationContext
body: <p>I am trying to parameterize cron expression and reading it from properties file. During this process I get following exception "Error creating bean with name 'springScheduleCronExample': Initialization of bean failed; nested exception is java.lang.IllegalStateException: Encountered invalid @Scheduled method 'cronJob': Cron expression must consist of 6 fields (found 1 in "${cron.expression}")". </p>
  
  <p>Then I found following <a href="https://stackoverflow.com/questions/34195290/spring-scheduled-cron-details-from-property-file-exception">post</a> </p>
  
  <p>Using that I cron expression is being read, only if I have </p>
  
  <p>AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
                     SpringScheduleCronExample.class); </p>
  
  <p>define in my main method. The issue that I am having is, I want to run this on server without main method, can anyone please help me with this.</p>
  
  <p>Here is my applicationContext.xml</p>
  
  <pre><code>&lt;?xml  version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:task="http://www.springframework.org/schema/task"
   xmlns:util="http://www.springframework.org/schema/util"
   xmlns:context="http://www.springframework.org/schema/context"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
          http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd"&gt;
  
      &lt;task:annotation-driven /&gt;
      &lt;util:properties id="applicationProps" location="application.properties" /&gt;
      &lt;context:property-placeholder properties-ref="applicationProps"  /&gt;
      &lt;bean class="com.hemal.spring.SpringScheduleCronExample" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>My SpringScheduleCronExample.java looks like this </p>
  
  <pre><code>package com.hemal.spring;
  
  import java.util.Date;
  import java.util.concurrent.atomic.AtomicInteger;
  
  import org.springframework.context.annotation.AnnotationConfigApplicationContext;
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.context.annotation.PropertySource;
  import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
  import org.springframework.scheduling.annotation.EnableScheduling;
  import org.springframework.scheduling.annotation.Scheduled;
  
  @Configuration
  @EnableScheduling
  @PropertySource("classpath:application.properties")
  public class SpringScheduleCronExample {
      private AtomicInteger counter = new AtomicInteger(0);
  
  
      @Bean
      public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() {
  
          return new PropertySourcesPlaceholderConfigurer();
      } 
  
      @Scheduled(cron = "${cron.expression}")
      public void cronJob() {
          int jobId = counter.incrementAndGet();
          System.out.println("Job @ cron " + new Date() + ", jobId: " + jobId);
      }
  
      public static void main(String[] args) {
  
             AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
                     SpringScheduleCronExample.class);
          try {
              Thread.sleep(24000);
          } catch (InterruptedException e) {
              e.printStackTrace();
          } finally {
             context.close();
          }
      }
  }
  </code></pre>
  
  <p>My application Properties has 
  cron.expression=*/5 * * * * ?</p>