title: Spring inject task executor in bean
body: <p>I'm using Spring Boot and I'm not able to inject a task executor in a service bean.
  Here's some code:</p>
  
  <pre><code>@Service
  public class ClassA {
   @Autowired
      private ThreadPoolTaskExecutor taskExecutor;
  
   public void doSht(){
       for(int i = 0; i&lt;this.taskExecutor.getMaxPoolSize(); i++){
           this.taskExecutor.execute(new ClassB());
       }
   }
  }
  </code></pre>
  
  <p>Class B:</p>
  
  <pre><code>public class ClassB implements Runnable {
  
      @Override
      public void run() {
          System.out.println("Class B running");
      }
  
  }
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>@Controller
  public class IndexController {
      @Autowired
      ClassA ca;
  
      @RequestMapping("/")
      public String index(){
          return "index";
      }
  
      @RequestMapping("test")
      public String test(ClassA ca){
          ca.doSht();
          return "test";
      }
  }
  </code></pre>
  
  <p>And here's the task executor configuration:</p>
  
  <pre><code>@SpringBootApplication
  public class App{
      @Bean
      public ThreadPoolTaskExecutor taskExecutor() {
          ThreadPoolTaskExecutor taskExecutor = new ThreadPoolTaskExecutor();
          taskExecutor.setCorePoolSize(5);
          taskExecutor.setMaxPoolSize(10);
          taskExecutor.setQueueCapacity(30);
          return taskExecutor;
      }
  
  
      public static void main(String[] args) throws Exception{
          SpringApplication app = new SpringApplication(App.class);
          app.run(args);
      }
  }
  </code></pre>
  
  <p>I want the ClassB instances being executed when a request comes to /test, but I get a NullPointerException because the task executor being not autowired into ClassA bean.</p>
  
  <p>What am I doing wrong?</p>