我正在尝试在两个不同路径中的两种不同方法上应用 @before 方面
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: 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 分支同时匹配的情况。那么应该绑定哪个匹配的参数或注释呢?这实在是很暧昧。
那么如何解决它呢?只需使用两个切入点/建议对,而不是仅使用一对。如果建议很复杂并且包含大量代码,您仍然可以将该代码分解为一个辅助方法,该方法采用JoinPoint
参数左右。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)