I have read at multiple stackoverflow questions that applicationContext.getbean is a bad idea.
Why is Spring's ApplicationContext.getBean considered bad?
I want to know if there is a better way of scanning beans of a given type in spring.
My use case is to get beans of a given type during spring start up and invoke some methods on those beans.
From what I know there are only two ways of doing this.
- Either autowire application context into a spring bean and use appContext.getBeansOfType.
Hook in a postprocessor and filter our beans of given type by
if(bean instance of type)
I feel hooking in a postprocessor just to process beans of one type is not a good idea. Because that will intercept all the bean initializations.
Can anyone suggest a better approach to solving my use case? (getBeans of a given type)