Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pointcut not working for generic interface

Tags:

java

spring

aop

I'm using Spring framework (2.5) and it's AOP features. I've a pointcut expression, like

@Pointcut("execution(public * org.springframework.batch.item.ItemReader+.read(..))")
public void itemReaderMethods() {}

Where the ItemReader interface is a Spring interface and it's signature is:

org.springframework.batch.item.ItemReader<T>

The interface has a method named as 'read' for which I want to apply the advise: the method signature is:

org.springframework.batch.item.ItemReader.read()

But, when I run my application with the above pointcut expression, I'm getting the below exception:

java.lang.IllegalArgumentException: warning no match for this type name: org.springframework.batch.item.ItemReader [Xlint:invalidAbsoluteTypeName]

My guess is that, since ItemReader is a generic interface, the pointcut is not matching properly. If that is the case, how can I write my pointcut expression to match the generic interfaces also?

like image 486
Veera Avatar asked Nov 27 '25 17:11

Veera


1 Answers

Generics don't seem to be a problem for me - I can create a test pointcut on Map operations:

@Around(value="execution(* java.util.Map.size(..))")

I didn't need to use Map+ either (I assume that is because we're using interfaces), and the generic nature of Map didn't matter either.

Are you sure that the ItemReader interface class is available and that you have implementations available? That's what the error message suggests (and which I can get if I put a dummy class name in my test pointcut). Maybe try logging/printing

Class.forName("org.springframework.batch.item.ItemReader")

and similarly for your expected implementation class?

like image 62
paulcm Avatar answered Nov 30 '25 00:11

paulcm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!