AOP Spring @AfterReturning没有正确调用Aspects方法

时间:2019-04-15 10:19:55

标签: java spring aop spring-aop aspect

我有一个注释。


@Target(value = {ElementType.METHOD, ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface MyCustomAnnotation{

}

我的Aspect类就是这样


@Component
@Aspect
public class MyCustomAsspect{

    @AfterReturning(
            pointcut="@annotation(MyCustomAnnotation)",
            returning="retVal")
    public void publishMessage(JoinPoint jp, Object retVal) throws Throwable {


    }
}

我的服务班级是

@Service
public class ServiceClass{

@MyCustomAnnotation
public Object someMethod(){
return new Object();
}

}

以上提到的类我不确定为什么我的方面不起作用。我是Spring AOP的新手。请帮助我,我将非常感激。

1 个答案:

答案 0 :(得分:1)

问题归因于切入点声明。如春季文档所述

  

@annotation-将匹配点限制为   连接点(在Spring AOP中执行的方法)具有给定的   注释

所以我要进行这项工作

{{1}}
相关问题