title: autowired object is null in spring TaskExecutor class
body: <p>I am trying to run a method using different thread using Spring TaskExecutor. I have an autowired dependecy,I am getting a NullPointerException .The autowired dependency is null. Please Help.</p>
  
  <p>The TaskExecutor class is below:</p>
  
  <pre><code>public class WebClientTaskExecutor {
  
      @Autowired
      WebClientService webClientService;
  
      public class SyncMails implements Runnable {
  
          private String userName;
  
          private Store store;
  
          public SyncMails(String userName, Store store) {
              this.userName = userName;
              this.store = store;
  
          }
  
          @Override
          public void run() {
              try {
                  System.out.println("inside sync mails run method");
  
                  String[] folderNames = { "inbox", "sent", "trash", "drafts" };
                  for (String folderName : folderNames) {
  //Null pointer exception in below line.webClientservice=null
                          int messageCount = WebClientTaskExecutor.this.webClientService.getMessageCount(
                                  folderName, this.store);
                          int dbLatestMessageNumber = WebClientTaskExecutor.this.webClientService
                                  .getLatestMessageNumberFromDb(folderName,
                                          this.userName, 1);
                          System.out.println("MEssage count----&gt;" + messageCount);
                          System.out.println("Latest message count dao---&gt;"
                                  + dbLatestMessageNumber);
                          if (messageCount &gt; dbLatestMessageNumber) {
                              WebClientTaskExecutor.this.webClientService.getMailsFromImap(folderName,
                                      messageCount, dbLatestMessageNumber + 1,
                                      this.store, this.userName);
                          }
  
                      }
                  } catch (MessagingException e) {
                      // TODO Auto-generated catch block
                      e.printStackTrace();
                  }
  
              }
  
              public String getUserName() {
                  return userName;
              }
  
              public void setUser(String userName) {
                  this.userName = userName;
              }
  
              public Store getStore() {
                  return store;
              }
  
              public void setStore(Store store) {
                  this.store = store;
              }
  
          }
  
  
          private TaskExecutor taskExecutor;
  
            public WebClientTaskExecutor(TaskExecutor taskExecutor) {
              this.taskExecutor = taskExecutor;
            }
  
            public void syncMails(String userName,Store store){
                System.out.println("web client service object----&gt;" + webClientService);
                this.taskExecutor.execute(new SyncMails(userName, store));
            }
      }
  </code></pre>
  
  <p>In controller,I am creating thrTaskExecutor object and giving it to WebClientTaskExecutor constructor.And starting the syncMails method.</p>
  
  <pre><code>ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
          executor.setCorePoolSize(10);
          executor.setMaxPoolSize(20);
          executor.setQueueCapacity(50);
          executor.initialize();
              WebClientTaskExecutor taskExecutor = new WebClientTaskExecutor(executor);
              taskExecutor.syncMails(userName, store);
  </code></pre>