Java Spring aop多个切入点&;但只有最后一条有效

Java Spring aop多个切入点&;但只有最后一条有效,java,spring,aop,Java,Spring,Aop,我已经创建了两个完全独立的SpringAOP切入点,它们将被编织到系统的不同部分。切入点用于两个不同的环绕建议,这些环绕建议将指向相同的Java方法 xml文件的外观: <aop:config> <aop:pointcut expression="execution(......)" id="pointcutOne" /> <aop:pointcut expression="execution(.....)" id="pointcurTwo" /&g

我已经创建了两个完全独立的SpringAOP切入点,它们将被编织到系统的不同部分。切入点用于两个不同的环绕建议,这些环绕建议将指向相同的Java方法

xml文件的外观:

<aop:config>
    <aop:pointcut expression="execution(......)" id="pointcutOne" />
    <aop:pointcut expression="execution(.....)" id="pointcurTwo" />

    <aop:aspect id="..." ref="springBean">
        <aop:around pointcut-ref="pointcutOne" method="commonMethod" />
        <aop:around pointcut-ref="pointcutTwo" method="commonMethod" />
    </aop:aspect>
</aop:config>


问题是只有最后一个切入点起作用(如果我改变顺序
pointcutOne
起作用,因为它是最后一个切入点)。我通过创建一个大切入点来实现它,但我希望它们分开。对于为什么每次只有一个切入点有效,有什么建议吗

尝试将切入点和建议放在
元素中。大概是这样的:

<aop:config>
  <aop:aspect id="aspect1" ref="springBean">
    <aop:pointcut expression="execution(......)" id="pointcutOne" />
    <aop:around pointcut-ref="pointcutOne" method="commonMethod" />
  </aop:aspect>

  <aop:aspect id="aspect2" ref="springBean">
    <aop:pointcut expression="execution(.....)" id="pointcurTwo" />
    <aop:around pointcut-ref="pointcutTwo" method="commonMethod" />
  </aop:aspect>
</aop:config>
@Aspect
public class Aspect1 {

    @Pointcut("execution(* *(..))")
    public void demoPointcut() {}

    @Around("demoPointcut()")
    public void demoAdvice(JoinPoint joinPoint) {}
}
这方面可能是这样的:

<aop:config>
  <aop:aspect id="aspect1" ref="springBean">
    <aop:pointcut expression="execution(......)" id="pointcutOne" />
    <aop:around pointcut-ref="pointcutOne" method="commonMethod" />
  </aop:aspect>

  <aop:aspect id="aspect2" ref="springBean">
    <aop:pointcut expression="execution(.....)" id="pointcurTwo" />
    <aop:around pointcut-ref="pointcutTwo" method="commonMethod" />
  </aop:aspect>
</aop:config>
@Aspect
public class Aspect1 {

    @Pointcut("execution(* *(..))")
    public void demoPointcut() {}

    @Around("demoPointcut()")
    public void demoAdvice(JoinPoint joinPoint) {}
}
更新:

使用切入点组合其他三个切入点的示例:

@Pointcut("traceMethodsInDemoPackage() && notInTestClass() " +
    "&& notSetMethodsInTraceDemoPackage()")
public void filteredTraceMethodsInDemoPackage() {}

我猜aop:aroung只是问题中的一个输入错误。同样的问题,这很奇怪。当我只有一个切入点时,它确实工作得很好,但它很快变得非常大。感谢您对使用注释的建议。我完全同意您的看法,它是一个比使用xml更好的解决方案。除了xml之外,我还有与注释类似的切入点,但我也想支持xml,因为它可以让主项目在不重新编译的情况下更改方面。这很奇怪。代理对象应该在joinpoint提供的方法之前和之后递归调用。如果它与一个切入点一起工作,那么您可以创建第三个切入点,将前两个切入点结合起来,并在around建议中使用它。使用注释效果很好,因此我想我至少会更新大部分方面以使用它而不是xml。只是要知道,我们需要重新编译以进行更改。谢谢你的帮助!我只是想知道,假设你有两个“周围”的建议,有不同的切入点。如果其中一个函数同时满足两个切入点呢。然后会发生什么。该函数是否会运行两次,因为您的两个建议都包含“point.continue()”。有人能解释一下吗?我看到只有一个元素包含在元素中。