0

ポイントカット宣言:

@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 バージョン) で Aspect をコンパイルすると、エラーが発生する"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){
...
}
4

1 に答える 1

1

Spring AOPmethod join points必要に応じてプロキシ化されたオブジェクトを作成するものに基づいているため、サポートのみをサポートしdynamic proxiesます (たとえば、ApplicationContext を使用している場合、Bean が からロードされた後に作成されますBeanFactory) 。

ステートメントを使用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()statement は、アドバイスを適用する場所を示す 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:

また、エラーは、あなたがアドバイスを守っていないことを示しています。技術的には、実行するたびに thisJoinPoint を構築する必要がないため、guard を使用するとコードが高速になります。したがって、意味をなさない場合は、無視してみてください

canNotImplementLazyTjp = ignore
multipleAdviceStoppingLazyTjp=ignore
noGuardForLazyTjp=ignore
于 2014-01-05T07:47:20.133 に答える