java - spring aop执行返回类型

标签 java spring aop aspectj

我 通过 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/

相关文章:

java - OSGi:条件权限管理员或用户管理员

java - Android action bar items 在 action bar 的左侧

java - 反射-EasyMock-ClassCastException

java - 使用 Java(PlayFramework-2.6 或 Plain Java)将数据 URI 上传到服务器

javascript - 将 JSP 数据表转换为 Jquery 数据表

azure - 多次读取 BrokeredMessage 正文

java - eclipse中的spring petclinic编译错误

java - 从 Autowiring bean 获取数据源时出现空指针异常

spring - 从对象本身获取 AOP 代理

java - 如何使用 ByteBuddy 代理现有对象