切入点不适用于通用接口 [英] Pointcut not working for generic interface
问题描述
我使用的是 Spring 框架 (2.5) 和它的 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() {}
ItemReader 接口 是一个 Spring 接口,它的签名是:
Where the ItemReader interface is a Spring interface and it's signature is:
org.springframework.batch.item.ItemReader<T>
该接口有一个名为read"的方法,我想为其应用建议:方法签名是:
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:警告不匹配此类型名称:org.springframework.batch.item.ItemReader [Xlint:invalidAbsoluteTypeName]
java.lang.IllegalArgumentException: warning no match for this type name: org.springframework.batch.item.ItemReader [Xlint:invalidAbsoluteTypeName]
我的猜测是,由于 ItemReader 是一个通用接口,因此切入点没有正确匹配.如果是这种情况,我如何编写切入点表达式以匹配通用接口?
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?
推荐答案
泛型对我来说似乎不是问题 - 我可以在 Map 操作上创建测试切入点:
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(..))")
我也不需要使用 Map+(我认为这是因为我们使用的是接口),而且 Map 的通用性质也不重要.
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.
您确定 ItemReader 接口类可用并且您有可用的实现吗?这就是错误消息所暗示的(如果我在测试切入点中放置一个虚拟类名,我可以获得).也许尝试记录/打印
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?
这篇关于切入点不适用于通用接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!