问题描述
我正在使用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() {}
是一个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?
这篇关于切入点不适用于通用接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!