AOP: error at ::0 inconsistent binding applying aop on two different methods

帅比萌擦擦* 提交于 2021-01-08 02:09:57

问题


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
    }
}

and I have my aspect class:

@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
    }
}

I am getting an error org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'objectMapperConfigurer' defined in class path resource [springfox/documentation/spring/web/SpringfoxWebMvcConfiguration.class]: BeanPostProcessor before instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.transaction.annotation.ProxyTransactionManagementConfiguration': Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: error at ::0 inconsistent binding

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


回答1:


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.

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.



来源:https://stackoverflow.com/questions/43331538/aop-error-at-0-inconsistent-binding-applying-aop-on-two-different-methods

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