什么是最简单的切入点表达式,它将拦截使用@Service注释的所有bean的所有公共方法?例如,我希望它会影响这个bean的两个公共方法:
@Service
public MyServiceImpl implements MyService {
public String doThis() {...}
public int doThat() {...}
protected int doThatHelper() {...} // not wrapped
}
最佳答案
这documentation应该非常有帮助.
我会创建两个单独的点切割,一个用于所有公共方法,一个用于所有使用@Service注释的类,然后创建第三个,它结合了另外两个的切入点表达式.
查看(7.2.3.1支持的切入点指示符)以供使用的指示符.我认为你是在寻找公共方法的“执行”指示符之后,以及用于查找注释的“注释”指示符.
然后看一下(7.2.3.2组合切入点表达式)来组合它们.
我在下面提供了一些代码(我没有测试过).它主要来自文档.
@pointcut("execution(public * *(..))") //this should work for the public pointcut
private void anyPublicoperation() {}
//@pointcut("@annotation(Service)") this might still work,but try 'within' instead
@pointcut("@within(Service)") //this should work for the annotation service pointcut
private void inTrading() {}
@pointcut("anyPublicoperation() && inTrading()")
private void TradingOperation() {}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。