title: Method annotated with @Bean is called directly. Use dependency injection instead
body: <p>I'm following a tutorial for Spring Batch and when I write the following code - IntelliJ is complaining that the tasklet(null) call in the job function is called directly:</p>
  <pre><code>Method annotated with @Bean is called directly. Use dependency injection instead.
  </code></pre>
  <p>I can get the error to go away if I remove the @Bean annotation from the job - but I want to know what's going on. How can I inject the bean there? Simply writing <code>tasklet(Tasklet tasklet(null))</code> gives the same error.</p>
  <pre><code>@Bean
  @StepScope
  public Tasklet tasklet(@Value(&quot;#{jobParameters['name']}&quot;) String name) {
      return ((contribution, chunkContext) -&gt; {
          System.out.println(String.format(&quot;This is %s&quot;, name));
          return RepeatStatus.FINISHED;
      });
  }
  
  @Bean
  public Job job() {
      return jobBuilderFactory.get(&quot;job&quot;)
              .start(stepBuilderFactory.get(&quot;step1&quot;)
                      .tasklet(tasklet(null))               // tasklet(null) = problem
                      .build())
              .build();
  }
  </code></pre>
  <p>asd</p>