アプリケーションコンテキストから取得した ShapeService があります。shapeService には Circle と Triangle が注入されます。shapeService に getCircle() と getTriangle() があります。また、ゲッターが呼び出されるたびにトリガーされるように構成されたアドバイスもあります。すべてのゲッターに適用できるように指定されたポイントカット式。したがって、 getCircle() または getTriangle() が呼び出されるたびに、アドバイスがトリガーされます。しかし、なぜそれが applicationContext.getBean() に対してトリガーされないのか疑問に思っていました。それもポイントカット式を満たすゲッターです。トリガーされない理由を理解するのを手伝ってくれる人はいますか。
@Aspect
@Component
public class LoggingAspect {
@Before("allGetters()")
public void loggingAdvice(JoinPoint joinPoint){
System.out.println(joinPoint.getTarget());
}
@Pointcut("execution(public * get*(..))")
public void allGetters(){}
}
これは、Bean を取得するメイン クラスです。Shapeservice の getter と circle の getter のみがトリガーされ、apllicationContext の getBean はトリガーされません
public class AopMain {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-config.xml");
ShapeService shapeService = ctx.getBean("shapeService", ShapeService.class);
System.out.println(shapeService.getCircle().getName());
}
}
ありがとう