簡體   English   中英

Spring AOP未檢測到自定義注釋

[英]Custom annotation not being detected by Spring AOP

因此,我一直在嘗試使用Spring AOP,但是一旦我開始使用自定義方法注釋,AOP就會停止工作。

這是注釋:

package com.test.annotations;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Performance {

}

方面:

package com.test.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


@Component
@Aspect
public class Audience {
    @Pointcut("@annotation(com.test.annotations.Performance)")
    public void performance() {
    }

    @Around("performance()")
    public void beforePerformance(ProceedingJoinPoint jointPoint) throws Throwable{
        System.out.println("The audience is getting ready for the show");

        jointPoint.proceed();

        System.out.println("The show is over, audience's leaving");
    }

}

使用自定義注釋的類:

package com.test.performers;

import com.test.annotations.Performance;
import com.test.exceptions.PerformanceException;

public interface Performer {
    @Performance
    void perform() throws PerformanceException;
}

最后是主要方法的相關部分。

Performer kenny = (Performer) context.getBean("guitarist");
kenny.perform();

Guitarist類正在實現表演者接口。

我已經環顧了幾個小時,看不到我在做什么錯。 謝謝 !

注釋中沒有繼承。 Guitaritst類中,當重寫perform()方法時,也應對其進行注釋。

暫無
暫無

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

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