문제

Maybe name of theme is bad. I try to explain clarity.

I have class:

public class A(){
   Field1 field1;
   Field2 field2;
   public void method1(){...}
   public void method2(){...}
   public void sourceMethod(ParameterClass parameter1){
     //some code
     method1();
     //some code
      method2();
     //some cdoe
  }
}

I will hook source method: ...

@Around(value = "execution(* A.sourceMethod(ParameterClass))")
    public void aroundSourceMethod(JoinPoint joinPoint){
      //I need to write my realization sourceMethod here
      // I want to invoke method1 and method2 here
}

Here I want to rewrite all code. But I need to invoke method1() and method2()

Is it possibly using AspectJ ?

도움이 되었습니까?

해결책

@Around(value = "execution(* A.sourceMethod(Parameter)) && target(target)")
public void aroundSourceMethod(JoinPoint joinPoint, Object target){
   // I need to write my realization sourceMethod here
   // I want to invoke method1 and method2 here
}

Target will contain the object which sourceMethod is executed on. Since you only advise A.sourceMethod(), you can assume that it is of type A, cast it to that and call its methods as you like:

((A) target).method1()
...

It's not pretty, but it should work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top