title: How to Autowire conditionally in spring boot?
body: <p>I have created one scheduler class</p>
  
  <pre><code>public class TestSchedulderNew {
  
  @Scheduled(fixedDelay = 3000)
  public void fixedRateJob1() {
  System.out.println("Job 1 running");
  }
  
  @Scheduled(fixedDelay = 3000)
  public void fixedRateJob2() {
  System.out.println("Job 2 running");
  }
  }
  </code></pre>
  
  <p>In configuration i have put @ConditionalOnProperty annotation to enable this on conditional purpose.</p>
  
  <pre><code> @Bean
  @ConditionalOnProperty(value = "jobs.enabled")
  public TestSchedulderNew testSchedulderNew() {
  return new TestSchedulderNew();
  }
  </code></pre>
  
  <p>Now in controller, i have created "stopScheduler" method to stop those scheduler , in this controller i have autowired 
  TestSchedulderNew class</p>
  
  <pre><code> @RestController
   @RequestMapping("/api")
   public class TestCont {
  
  private static final String SCHEDULED_TASKS = "testSchedulderNew";
  
   @Autowired
   private ScheduledAnnotationBeanPostProcessor postProcessor;    /]
  
   @Autowired
   private TestSchedulderNew testSchedulderNew;
  
  
   @GetMapping(value = "/stopScheduler")
   public String stopSchedule(){
    postProcessor.postProcessBeforeDestruction(testSchedulderNew, 
     SCHEDULED_TASKS);
    return "OK";
    }
   }     
  </code></pre>
  
  <p>Now the problem is if conditional property is false then i get below exception</p>
  
  <pre><code>   Field testSchedulderNew in com.sbill.app.web.rest.TestCont required a bean of type 'com.sbill.app.schedulerJob.TestSchedulderNew
  </code></pre>
  
  <p>In case of true everything works fine,</p>
  
  <p>Do we have any option to solve this ?</p>