Spring Aspects/Advisor的初始化顺序 [英] Initialization Order of Spring Aspects / Advisors

查看:193
本文介绍了Spring Aspects/Advisor的初始化顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种方法可以配置Spring中的不同方面(或更准确地说,是它们相应的Advisor)的初始化方式?请注意,我不是在讨论建议顺序,而是方面的初始化.

此问题的背景是Aspect A依赖于Service X的用例,应由Aspect B建议.但是,由于Aspect A首先被初始化并强制创建Service X,因此Aspect B不会应用于该服务.

如何在不使Service X依赖于Aspect B的情况下更改初始化顺序(这将是一种变通方法,因为它强制执行所需的顺序,但服务永远不必处理其各个方面...)?/p>

如果您想了解我的问题的大概况,请解决方案

一个方面通常只是一个带有@Aspect注释的类,该类也带有@Component注释或具有相应的<bean>定义.换句话说,它只是一个bean.

定义Bean初始化顺序的唯一方法是使用depends-on属性(或@DependsOn),或者使用导入上下文的顺序进行操作.

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.

解决方案

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.

这篇关于Spring Aspects/Advisor的初始化顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆