简体   繁体   English

切入点不适用于通用接口

[英]Pointcut not working for generic interface

I'm using Spring framework (2.5) and it's AOP features. 我正在使用Spring framework(2.5)及其AOP功能。 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: ItemReader接口是Spring接口,其签名为:

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: 该接口有一个名为“ read”的方法,我要对其应用此建议:方法签名为:

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] java.lang.IllegalArgumentException:警告与此类型名称不匹配:org.springframework.batch.item.ItemReader [Xlint:invalidAbsoluteTypeName]

My guess is that, since ItemReader is a generic interface, the pointcut is not matching properly. 我的猜测是,由于ItemReader是通用接口,因此切入点无法正确匹配。 If that is the case, how can I write my pointcut expression to match the generic interfaces also? 如果是这种情况,我该如何编写切入点表达式以匹配通用接口?

Generics don't seem to be a problem for me - I can create a test pointcut on Map operations: 泛型对我来说似乎不是问题-我可以在Map操作上创建测试切入点:

@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. 我也不需要使用Map +(我想那是因为我们正在使用接口),并且Map的通用性质也没关系。

Are you sure that the ItemReader interface class is available and that you have implementations available? 您确定ItemReader接口类可用并且您有可用的实现吗? 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? 和您预期的实现类类似?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM