我创建了一个适用于所有公共方法的简单方面:
@Aspect
@Component
public class MyAspect {
@Pointcut("execution(public * *(..))")
private void anyPublicOperation() {
}
@Before("anyPublicOperation()")
private void beforePointCut(){
System.out.println("Inside before pointcut of MyAspect");
}
}
我有以下Java配置:
@Configuration
//Enable AspectJ auto proxying
@EnableAspectJAutoProxy
@ComponentScan(basePackages={"com.examples"})
public class Config {
//Declare a bean
@Bean
public MyAspect myAspectProgram() {
return new MyAspect();
}
}
当我使用AnnotationConfigApplicationContext
类加载配置时,我遇到异常:
Caused by: org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'myAspectProgram': Requested bean is currently in creation: Is there an unresolvable circular reference?
如果我更改了切入点表达式,那么我没有任何异常,程序运行正常。
当我将切入点表达式设为@Pointcut("execution(public * *(..))")
时,为什么会出现问题?