I'm aware of the fact that the order of bean loading is implicitly determined by dependencies and transitive dependencies.
Imagine you have a set of annotated beans that provide you with some sort of metadata that you want to apply to another set of AwareBeans. So that only after you gather all the metadata from N beans, only after that you can post process the AwareBeans. You typically use org.springframework.beans.factory.config.BeanPostProcessor
for this kind of stuff. How to deal with the order though? I think that even setting up depends-on
explicitly doesn't take precedence over dependencies as to loading order, right?
There is an interface org.springframework.core.Ordered
that just determines on the order of beanPostProcessors being applied, but not the order of beans.
I could use org.springframework.beans.factory.config.BeanFactoryPostProcessor
but bean definition has not enough information before bean instantiation. For example beanDef.getBeanClass()
returns bean class name etc.
Is that any other way you could think of how to do what I want ?
I solved it by using org.springframework.beans.factory.config.BeanFactoryPostProcessor
and loading classes by classloader so that I can use Reflection to grab the annotations. I think it shouldn't break anything because afterwards when spring is gonna classload the bean classes classloader checks whether the class is loaded already and if so it doesn't load it. Otherwise it loads it.