Вопрос

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