AOP:在:: 0不一致的绑定处发生错误,将aop应用于两种不同的方法 [英] AOP: error at ::0 inconsistent binding applying aop on two different methods

查看:64
本文介绍了AOP:在:: 0不一致的绑定处发生错误,将aop应用于两种不同的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在两个不同路径的两个不同方法上应用@before方面

I am trying to apply a @before aspect on two different methods in two different paths

class Service1{
    public Object applyX(X x){
     //code
    }
}

class Service2{
    public OtherObject applyY(Y y){
     //code
    }
}

我有我的方面类:

@Aspect
@Component
public class MyProcessor {

    @Before("execution(* com.a.b.c.Service1.applyX"
            + " (com.xp.X)) "
            + "&& args(engineEvaluationRequest) || "
            + "execution(* com.a.b.d.Service2.applyY"
            + " (com.yp.Y))"
            + "&& args(y)")
    public void process(X x ,Y y){
        //code
    }
}

我收到错误消息 org.springframework.beans.factory.BeanCreationException:创建类路径资源[springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class]中定义的名称为'objectMapperConfigurer'的bean时出错:bean的实例化失败;嵌套的异常是org.springframework.beans.factory.BeanCreationException:创建名称为"org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration"的bean时出错:bean的初始化失败;嵌套的异常是java.lang.IllegalArgumentException:绑定不一致时:: 0发生错误

我不明白出了什么问题.我可以得到帮助吗?谢谢!

and I don't understand what went wrong. can I get help? Thanks!

推荐答案

错误消息不一致的绑定已经说过:您与 args()的变量绑定在此范围内不一致由于 || (逻辑或)运算符的缘故,它是模棱两可的.找到 X 并可以将其绑定,也可以将 Y 绑定,但另一个未定义.您可能已经假设,如果未绑定变量,则默认为 null ,但是这种假设是错误的.AspectJ不能那样工作.您的切入点必须明确地将变量绑定到相应的建议参数.

The error message inconsistent binding already says it: Your variable binding with args() is inconsistent insofar as it is ambiguous due to the || (logical or) operator. Either X is found and can be bound or Y, but the other one would be undefined. You might have assumed that if a variable is not bound it defaults to null, but this assumption is wrong. AspectJ does not work like that. Your pointcut must bind variables unambiguously to the corresponding advice parameters.

那么如何解决呢?只需使用两个切入点/建议对,而不是一对.如果建议很复杂并且包含很多代码,您仍然可以使用 JoinPoint 参数左右,将该代码分解为一个辅助方法.

So how can you fix it? Just use two pointcut/advice pairs instead of just one. If the advice is complex and contains a lot of code you can still factor out that code into a helper method taking a JoinPoint parameter or so.

这篇关于AOP:在:: 0不一致的绑定处发生错误,将aop应用于两种不同的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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