问题
Is there a way to configure in which way different Aspects (or their corresponding Advisors to be more precise) in Spring are initialized? Note that I am not talking about the advice order, but the initialization of the aspects.
The background of this question is a use case with Aspect A dependent on Service X which should be advised by Aspect B. However, as Aspect A gets initialized first and enforces the creation of Service X, Aspect B is not applied to the service.
How can I change the initialization order without making Service X dependent on Aspect B (this would be a workaround as it enforces the desired order, but a service should never have to deal with its aspects...)?
If you want the big picture of my issue, here is another question which led me to asking this one.
回答1:
An aspect is typically just an @Aspect annotated class that is also annotated with @Component or that has a corresponding <bean> definition. In other words, it is just a bean.
The only ways to define the order that beans should be initialized is with the depends-on property (or @DependsOn) or by playing with the order in which you import contexts.
来源:https://stackoverflow.com/questions/21631297/initialization-order-of-spring-aspects-advisors