そのため、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;
}
最後に、main メソッドの関連部分です。
Performer kenny = (Performer) context.getBean("guitarist");
kenny.perform();
Guitarist クラスは、演奏者インターフェースを実装しています。
私は数時間見回してきましたが、何が間違っているのかわかりません。ありがとうございました !