AspectJ 匹配 return 类型作为与泛型的接口

AspectJ matching return type as interface with generics

我正在尝试创建一个 AspectJ 方面来拦截具有通用接口的返回方法。

这是我的 AspectJ

@AspectJ
public class MyAspect {

    @AfterReturning("execution(java.util.Collection+<mypackage.MyAbstractEntity+> mypackage.mvc.controllers..*.*(..))", returning = "list")
    public doStuff(JoinPoint j, Collection<MyAbstractEntity> list) {
    }
}

这是我的class,我想编织成:

package mypackage.mvc.controller;

public class MyController {
    // MyEntity extends MyAbstractEntity
    public List<MyEntity> findAll() {
    }
}

我做错了什么?

已解决!

将"plus"放在泛型定义之后("plus"表示"classes that extends it"):

java.util.Collection<mypackage.MyAbstractEntity+>+

并将 "list" 收缩为 "?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) {
    }
}