mardi 21 mars 2017

How to get parameter name in aspectj advice class?

I am asking this question with my limited knowledge of java reflection and AOP.

Background:

I am using annotation based advice in my application. Further to get the method parameter which I need to use in my advice I am using spring EL. See below examples: In first example i want to use second parameter to do my work, whereas in second example I am using a POJO and want to use its "id" field.

@MyAnnotation(param = "args[1]")
public void someMethod(int param1, String param2) {
  return null;
}

@MyAnnotation(param = "args[0].id")
public void someMethod(SomeObject someObject) {
  return null;
}

But what I actually want is, to get my hands on the parameter names in my AOP. So that I can use @MyAnnotation(param = "param1") or @MyAnnotation(param = "someObject.id") instead.

From what I have known, you can not get parameter name using reflection. But recently I came across Spring cache abstraction(link), where I see:

@Cacheable(cacheNames="books", key="#isbn")
public Book findBook(ISBN isbn, boolean checkWarehouse, boolean includeUsed)

Can someone put some light here, how I can achieve similar behavior.





Aucun commentaire:

Enregistrer un commentaire