我有一个新方面,我想应用 @Around
一个用 @HystrixCommand
注释的服务方法。由于注释的存在,HystrixCommandAspect
会自动应用。
但是,HystrixCommandAspect
没有定义@Order
,我怀疑这意味着它默认为Integer.MAX_VALUE
(即它应该最后执行)。我需要我的方面最后运行,因为 HystrixCommandAspect
在不同的线程上执行服务方法,而我的方面需要在该线程上运行(原因在这里可能并不重要,但它涉及线程本地存储)。
似乎当@Order
中存在平局时,顺序是由Spring的组件扫描以某种方式确定的。有没有办法手动指定 Spring 应用这些方面的顺序(假设我无法更改 HystrixCommandAspect
的 @Order
)?
最佳答案
您可以尝试使用@DeclarePrecedence
,例如:
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.DeclarePrecedence;
@Aspect
@DeclarePrecedence("*, com.example.HystrixCommandAspect, com.example.YourCustomAspect")
public class AspectOrder {
}
可能需要您切换到 AspectJ。
关于java - 在 Spring 中订购第三方 Aspect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46451231/