Spring AOP错误无法懒惰地为此建议构建thisJoinPoint [英] Spring Aop Error Can not build thisJoinPoint lazily for this advice

查看:0
本文介绍了Spring AOP错误无法懒惰地为此建议构建thisJoinPoint的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

切入点声明:

@Pointcut(value="com.someapp.someservice.someOperation() && args(t,req)",argNames="t,req")
private void logOperationArg(final String t,final String req)
{
}

建议声明未编译:

@Before(value="logOperationArg(t,req)")
public void logBeforeOperationAdvice(JoinPoint jp, final String t, final String req){
...
}

使用AspectJ-maven-plugin(1.5版)编译方面时,出现错误"can not build thisJoinPoint lazily for this advice since it has no suitable guard [Xlint:noGuardForLazyTjp]"

但编译相同的建议时不使用JoinPoint参数。

建议声明汇编:

@Before(value="logOperationArg(t,req)")
public void logBeforeOperationAdvice(final String t, final String req){
...
}

推荐答案

Spring AOP仅支持method join points,因为它基于dynamic proxies在需要时创建代理对象(例如,如果您使用的是ApplicationContext,则它将在从BeanFactory加载Bean后创建)

使用execution()语句匹配作为方法执行的连接点。

例如:

class LogAspect {

@Before("execution(* com.test.work.Working(..))")
public void beginBefore(JoinPoint join){

System.out.println("This will be displayed before Working() method will be executed");
}

现在如何声明您的BO:

//.. declare interface

然后:

class BoModel implements SomeBoInterface {

public void Working(){
System.out.println("It will works after aspect");
     }
}

execution()语句是PointCut表达式,用于告知应将建议应用于何处。

如果您喜欢使用@PointCut,可以这样做:

class LogAspect {

//define a pointcut
@PointCut(
        "execution(* com.test.work.SomeInferface.someInterfaceMethod(..))")
     public void PointCutLoc() {
}

@Before("PointCutLoc()")
public void getBefore(){
System.out.println("This will be executed before someInterfaceMethod()");
      }

}

第2部分:

此外,该错误还表明您没有保护您的建议。从技术上讲,Guard使您的代码更快,因为您不需要在每次执行它时都构造thisJoinPoint。因此,如果没有意义,您可以尝试忽略它

canNotImplementLazyTjp = ignore
multipleAdviceStoppingLazyTjp=ignore
noGuardForLazyTjp=ignore

这篇关于Spring AOP错误无法懒惰地为此建议构建thisJoinPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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