gpt4 book ai didi

java - spring aop执行返回类型

转载 作者:行者123 更新时间:2023-11-30 06:12:50 25 4
gpt4 key购买 nike

我通过 AspectJ 拦截方法。我需要在切入点表达式 execution(* *.*(..)) 添加返回类型 TestObj。我怎样才能做到这一点?

@Around("@annotation(interceptor) && execution(* *.*(..)) && args(argType, ..)")
public Object logAction(ProceedingJoinPoint joinPoint, Interceptor interceptor, TestObj argType) throws Throwable {
// do smth
}

最佳答案

execution() 表达式支持返回类型过滤。如果您需要返回类型为 TestObj 或其任何子类型,则以下内容应该有效:

@Around("@annotation(interceptor) && execution(* TestObj *.*(..)) && args(argType, ..)")
public Object logAction(ProceedingJoinPoint joinPoint, Interceptor interceptor, TestObj argType) throws Throwable {

您可以找到更多in the official docs, Chapter 2. Annotations :

execution(public (@Immutable *) org.xyz..*.*(..))

The execution of any public method in a package with prefix org.xyz, where the method returns an immutable result.

关于java - spring aop执行返回类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49852625/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com