AOP:在两个不同的方法上应用aop的:: 0不一致绑定时出错(AOP: error at ::0 inconsistent binding applying aop on two different

编程入门 行业动态 更新时间:2024-10-15 14:12:48
AOP:在两个不同的方法上应用aop的:: 0不一致绑定时出错(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 } }

我有我的方面课:

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

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

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!

最满意答案

错误消息inconsistent binding已经说明了:你的变量与args()绑定是不一致的,因为它是由于||不明确 (逻辑或)运算符。 找到X并且可以绑定或Y ,但另一个是未定义的。 您可能假设如果变量未绑定,则默认为null ,但这种假设是错误的。 AspectJ并不像那样工作。 您的切入点必须明确地将变量绑定到相应的建议参数。

那你怎么解决它? 只需使用两个切入点/建议对,而不只是一个。 如果建议很复杂并且包含大量代码,您仍然可以将该代码分解为一个带有JoinPoint参数的辅助方法。

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.

更多推荐

class,public,springframework,bean,电脑培训,计算机培训,IT培训"/> <meta name=&

本文发布于:2023-07-30 18:54:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1338888.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:两个   方法   aop   AOP   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!