我有一個從應用程序上下文獲得的ShapeService。 shapeService注入了一個Circle和Triangle。我的shapeService中有getCircle()和getTriangle()。我也有一個建議,配置爲每當調用getter時觸發。指定的切入點表達式使其適用於所有獲取者。所以每當getCircle()或getTriangle()被調用時,都會觸發建議。但我想知道爲什麼沒有爲applicationContext.getBean()觸發。這也是一個滿足切入點表達式的getter。任何人都可以幫我找出爲什麼它沒有被觸發。getBean()沒有被觸發的AOP通配符
@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和圓形的吸氣劑得到觸發,而不是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());
}
}
感謝