AOP:在 ::0 处出现错误,在两种不同的方法上应用 aop 时绑定不一致
AOP: error at ::0 inconsistent binding applying aop on two different methods
我正在尝试在两个不同路径中的两个不同方法上应用@before 方面
class Service1{
public Object applyX(X x){
//code
}
}
class Service2{
public OtherObject applyY(Y y){
//code
}
}
我有我的一面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
}
}
我遇到错误 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
而且我不明白哪里出了问题。我能得到帮助吗?
谢谢!
错误消息 inconsistent binding
已经说明:您与 args()
的变量绑定不一致,因为 ||
(逻辑或)运算符不明确。 X
找到并可以绑定或 Y
,但另一个未定义。您可能假设如果一个变量没有绑定它默认为 null
,但这个假设是错误的。 AspectJ 不是那样工作的。您的切入点必须明确地将变量绑定到相应的通知参数。
编辑:因为 ||
是一个逻辑或,因此是非排他性的(与 XOR
不同),甚至可能会发生两个 OR 分支同时匹配的情况。那么应该绑定哪个匹配的参数或注解呢?这个真的很暧昧
那你怎么解决呢?只需使用两对 pointcut/advice 而不是一对。如果建议很复杂并且包含大量代码,您仍然可以将该代码提取到带有 JoinPoint
左右参数的辅助方法中。
我正在尝试在两个不同路径中的两个不同方法上应用@before 方面
class Service1{
public Object applyX(X x){
//code
}
}
class Service2{
public OtherObject applyY(Y y){
//code
}
}
我有我的一面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
}
}
我遇到错误 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
而且我不明白哪里出了问题。我能得到帮助吗? 谢谢!
错误消息 inconsistent binding
已经说明:您与 args()
的变量绑定不一致,因为 ||
(逻辑或)运算符不明确。 X
找到并可以绑定或 Y
,但另一个未定义。您可能假设如果一个变量没有绑定它默认为 null
,但这个假设是错误的。 AspectJ 不是那样工作的。您的切入点必须明确地将变量绑定到相应的通知参数。
编辑:因为 ||
是一个逻辑或,因此是非排他性的(与 XOR
不同),甚至可能会发生两个 OR 分支同时匹配的情况。那么应该绑定哪个匹配的参数或注解呢?这个真的很暧昧
那你怎么解决呢?只需使用两对 pointcut/advice 而不是一对。如果建议很复杂并且包含大量代码,您仍然可以将该代码提取到带有 JoinPoint
左右参数的辅助方法中。