在方面中读取注释属性 [英] Reading annotation property in aspect

查看:78
本文介绍了在方面中读取注释属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何读取方面的注释属性值?

How to read annotation property value in aspect?

我希望对所有带有 @Transactional(readonly = false) 注释的关节点执行 Around 建议strong>.

I want my Around advice to be executed for all joint points annotated with @Transactional(readonly=false).

@Around("execution(* com.mycompany.services.*.*(..)) "
+ "&& @annotation(org.springframework.transaction.annotation.Transactional)")
public Object myMethod(ProceedingJoinPoint pjp) throws Throwable {
}

推荐答案

您可以在不手动处理签名的情况下执行此操作(这种方式(argNames用于在没有调试信息的情况下进行编译时保留参数名称):

You can do it without manual processing of signature, this way (argNames is used to keep argument names when compiled without debug information):

@Around(
    value = "execution(* com.mycompany.services.*.*(..)) && @annotation(tx)",
    argNames = "tx") 
public Object myMethod(ProceedingJoinPoint pjp, Transactional tx) 
    throws Throwable {
    ...
} 

请参见 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆