应用于所有公共方法的AOP提供BeanCreationException异常

时间:2015-08-14 09:28:51

标签: spring spring-aop

我创建了一个适用于所有公共方法的简单方面:

@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 * *(..))")时,为什么会出现问题?

0 个答案:

没有答案