java注释还能运行_JAVA建议注释会运行两次?

就我而言,我使用以下建议:

@Around(value = "@annotation(MyAnnotation) && args(MyArgs)")

一旦将MyAnnotation添加到方法并且MyArgs也将被检索,它就可以正常工作.

@MyAnnotation(type = MyType.CREATE)

public void add(MyArgs) {

...

}

但是在这个post中,它说:

The errors that can and will occur

Using only annotations creates another problem that we don’t need to think about while using patterns; It will make our advice run twice(or more), because the annotation pointcut don’t specify if it should be run during execution or initialization.

根据我的理解,似乎一旦达到连接点并满足条件,建议应该运行(然后我的建议将运行两次 – 调用和执行).我应该使用以下建议来避免它.

@Around(value = "@annotation(MyAnnotation) && execution(* *(..)) && args(MyArgs)")

但我调试了我的代码,它只运行一次而不添加执行(* *(..)).

这是正确的吗?或者不是建议运行的方式?

更新时间2018-04-16

@Nandor是对的,我使用的是Spring AOP而不是AspectJ.我开始了一个maven demo,清楚地表明了他的观点.谢谢,Nandor.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值