aspectj切入点/建议仅适用于*

时间:2012-07-05 00:22:16

标签: java aop aspectj

我在让方面正常工作方面遇到了一些麻烦。出于某种原因,他们似乎只在我真正了解应用方面的位置时才会工作。在四个切入点/建议中,只有最后一个匹配并输出任何内容。我在这里缺少什么?

public aspect VerboseAspect
{
    after(Game game) returning:
            call(* Game.addPlayer(Player))
            && target(game) {
        System.out.println("addPlayer(Player): player has been added");
    }

    after(Game game) returning:
            call(* Game.addPlayer(..))
            && target(game) {
        System.out.println("addPlayer(..): player has been added");
    }

    after(Game game) returning:
            call(* Game.*(Player))
            && target(game) {
        System.out.println("*(Player):player has been added");
    }

    after(Game game) returning:
            call(* Game.*(..))
            && target(game) {
        System.out.println("*(..):player has been added");
    }
}

Java类:

public class Game {
    public void addPlayer(Player player) {
        System.out.println("inside class");
        this.players.add(player);
    }
}

输出:

inside class
*(..):player has been added

1 个答案:

答案 0 :(得分:0)

(评论,但太长了。)

您使用的是哪种版本的AspectJ?你是怎么建的?蚂蚁? Maven的?其他

它在IntelliJ中对我很好;运行这个:

public static void main(String[] args) {
    Game g = new Game();
    g.addPlayer(new Player());
}

产地:

inside class
addPlayer(Player): player has been added
addPlayer(..): player has been added
*(Player):player has been added
*(..):player has been added