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

AOP Spring @AfterReturning not calling the aspects method properly

我有注释。


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

}

我的长相class就是这样


@Component
@Aspect
public class MyCustomAsspect{

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


    }
}

我的服务 class 是

@Service
public class ServiceClass{

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

}

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

问题是由于切入点声明引起的。正如 spring 文档所说

@annotation - limits matching to join points where the subject of the join point (method being executed in Spring AOP) has the given annotation

所以我下令完成这项工作

@Aspect
public class MyCustomAsspect{

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


    }
}