AspectJ将返回类型匹配为泛型接口 [英] AspectJ matching return type as interface with generics
本文介绍了AspectJ将返回类型匹配为泛型接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图创建一个AspectJ Aspect来拦截具有通用接口的返回方法.
I'm trying to create an AspectJ Aspect to intercept the returning methods that has a generic interface.
这是我的AspectJ
This is my AspectJ
@AspectJ
public class MyAspect {
@AfterReturning("execution(java.util.Collection+<mypackage.MyAbstractEntity+> mypackage.mvc.controllers..*.*(..))", returning = "list")
public doStuff(JoinPoint j, Collection<MyAbstractEntity> list) {
}
}
这是我想加入的班级:
package mypackage.mvc.controller;
public class MyController {
// MyEntity extends MyAbstractEntity
public List<MyEntity> findAll() {
}
}
我在做什么错了?
推荐答案
已解决!
在泛型定义后加上"plus"("plus"表示扩展它的类"):
Put the "plus" after the generics definition ("plus" means "classes that extends it"):
java.util.Collection<mypackage.MyAbstractEntity+>+
然后将列表"收缩为?扩展":
And contract the "list" as "? extends":
public doStuff(JoinPoint j, Collection<? extends MyAbstractEntity> list) {
代码如下:
@AspectJ
public class MyAspect {
@AfterReturning("execution(java.util.Collection<mypackage.MyAbstractEntity+>+ mypackage.mvc.controllers..*.*(..))", returning = "list")
public doStuff(JoinPoint j, Collection<MyAbstractEntity> list) {
}
}
这篇关于AspectJ将返回类型匹配为泛型接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文