Search code examples
javaspringaopaspectjspring-aop

How to target aspect to method with argument of certain type?


If I write my aspect

@Before("args(data)")
public void beforeMethod( MyParam data ) {
    // ...
}

it will handle on method

public void m1(MyParam param){};

If I write aspect as

@Before("args(data,..)")
public void beforeMethod( MyParam data ) {
    // ...
}

it will handle on method

public void m2(MyParam param, OtherParam param2, Object smthElse){};

But MyParam param should be first.

The question is: how to configurate @Before("args(?)") to match methods where MyParam param will be not first parameter like here?

@Before("args(?)")
public void m3(OtherParam param2, MyParam param, Object smthElse){};

Solution

  • Could not test but this might be a way of doing this -

    args(*, param, ..)