1

My problem is that I my pointcut expression doesn't seem to match a method call and therefore is not executed. I suspect it has to do with generics in the parameter list.

The method I am trying to match has the following signature (actual names obfuscated):

public <T> ResponseEntity<T> doSomeAction(String a, Class<T> b, Object c, String d, String e) {
}

There is another method call that has the following signature that I'm not trying to match, but figure I could filter out by argument numbers. The only difference is that it has one less parameter (i.e. no String e).

public <T> ResponseEntity<T> doSomeAction(String a, Class<T> b, Object c, String d) {
}

The pointcut expression used is

@Before("execution (* packageNames.doSomeAction(..))
public void doAdvce(JointPoint joinPont) {
}

Some search, I did find something related, but I can't say I understand it.

Anyone able to shed some light on this?

mymirs
  • 11
  • 1
  • Welcome to SO. Your snippets do not contain enough information to answer the question. I need to see full classes with package names, imports, full aspect too. Please be advised to learn what an [MCVE](https://stackoverflow.com/help/mcve) is and how to ask good questions, then edit your question and notify me in a comment. – kriegaex Jan 28 '20 at 04:12
  • The method with the given signature can be adviced provided the point cut expression is valid. The one provided with the question is incorrect/invalid.Share a complete example or the relevant classes (Configuration,Aspect class,Class with method to intercept) so that we can help – R.G Jan 28 '20 at 04:54

2 Answers2

0

According to spring documentation, https://docs.spring.io/spring/docs/4.0.x/spring-framework-reference/html/aop.html you may specify the expected parameters explicitly like

execution(* doSomeAction(java.lang.String,java.lang.Class,java.lang.Object,java.lang.String,java.lang.String))
lazylead
  • 1,453
  • 1
  • 14
  • 26
0

You cannot match based on the generic of an argument, as stated in the Spring Framework reference documentation (Collection<T> is used as an example, but it seems this affects all generics). Spring recommends to do the following:

To achieve something similar to this, you have to type the parameter to Collection<?> and manually check the type of the elements.

So try this:

public <T> ResponseEntity<T> doSomeAction(String a, Class<?> b, Object c, String d, String e) {
}
Daniel
  • 458
  • 5
  • 16