title: Spring: how to register an anonymous class to the Bean Factory
body: <p>In Spring (Boot 2), is there a way to register an anonymous class to the Bean Factory <strong>inside a method</strong>? (Register as a Component for example )  </p>
  
  <p>Example: I want to to register "taskletInstance" as a Component so it's aware of the Spring Context. I can achieve this by taking it outside the method and annotate as @Bean. So I have 2 Bean annotated methods. But I am curious if I can do it inside the updateStep method:</p>
  
  <pre><code>@Bean
  @Qualifier("myStep")
  public Step handleStep() {
  
      Tasklet taskletInstance = new AbstractTasklet() {
          @Override
          public Data handleData(Data data) {
              //handle data
              return data;
          }
      };
  
      return stepBuilderFactory.get("handleStep").tasklet(taskletInstance).build();
  }
  </code></pre>