簡體   English   中英

AOP Spring @AfterReturning沒有正確調用Aspects方法

[英]AOP Spring @AfterReturning not calling the aspects method properly

我有一個注釋。


@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的新手。 請幫助我,我將非常感激。

問題是由於切入點聲明引起的。 如春季文件所述

@annotation-將匹配點限制為其中連接點的主題(在Spring AOP中執行的方法)具有給定注釋的連接點

所以我要使這項工作

@Aspect
public class MyCustomAsspect{

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


    }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM