aspect 方法入参 获取_spring – 在自定义注释的Aspect中传递方法参...

我正在尝试使用与org.springframework.cache.annotation.Cacheable类似的东西:

自定义注释:

@Target(ElementType.METHOD)

@Retention(RetentionPolicy.RUNTIME)

@Documented

public @interface CheckEntity {

String message() default "Check entity msg";

String key() default "";

}

方面:

@Component

@Aspect

public class CheckEntityAspect {

@Before("execution(* *.*(..)) && @annotation(checkEntity)")

public void checkEntity(JoinPoint joinPoint, CheckEntitty checkEntity) {

System.out.println("running entity check: " + joinPoint.getSignature().getName());

}

}

服务:

@Service

@Transactional

public class EntityServiceImpl implements EntityService {

@CheckEntity(key = "#id")

public Entity getEntity(Long id) {

return new Entity(id);

}

}

我的IDE(IntelliJ)没有看到与key =“#id”用法有什么特别之处,相比之下,Cacheable的类似用法与纯文本的颜色不同.我提到IDE部分只是作为一个提示,如果它有帮助,它看起来像IDE事先知道这些注释或它只是意识到我的例子中不存在的一些连接.

checkEntity.key中的值为“#id”而不是预期的数字.

我尝试使用ExpressionParser,但可能没有以正确的方式.

在checkEntity注释中获取参数值的唯一方法是访问arguments数组,这不是我想要的,因为这个注释也可以在具有多个参数的方法中使用.

任何的想法?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值