In Spring (Boot 2), is there a way to register an anonymous class to the Bean Factory inside a method? (Register as a Component for example )
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:
@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();
}