Initialization Order of Spring Aspects / Advisors

て烟熏妆下的殇ゞ 提交于 2019-12-11 12:57:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!