Search code examples
javaspring-bootspring-aop

Bean 'advisor' of type [org.springframework.aop.support.DefaultPointcutAdvisor] is not eligible for getting processed by all BeanPostProcessors


I have a configuration class like this,

@Configuration
@EnableAspectJAutoProxy
public class Config {

   @Bean
   public Advisor advisor() {
        AspectJExpressionPointcut ajp = new AspectJExpressionPointcut();
        ajp.setExpression("execution(public * my.package..*.*(..))");
        return new DefaultPointcutAdvisor(ajp, interceptor());
    }
}

And whenever the project is starting I am getting the following warning.

Bean 'advisor' of type [org.springframework.aop.support.DefaultPointcutAdvisor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)

Why I am getting this warning. How can I fix this?


Solution

  • This is a quote from Spring documentation

    BeanPostProcessors and AOP auto-proxying

    Classes that implement the BeanPostProcessor interface are special, and so they are treated differently by the container. All BeanPostProcessors and their directly referenced beans are instantiated on startup, as part of the special startup phase of the ApplicationContext. Next, all those BeanPostProcessors are registered in a sorted fashion - and applied to all further beans. Because AOP auto-proxying is implemented as a BeanPostProcessor itself, no BeanPostProcessors or directly referenced beans are eligible for auto-proxying, and thus do not have aspects woven into them.

    For any such bean, you should see an info log message: “Bean foo is not eligible for getting processed by all BeanPostProcessor interfaces (for example: not eligible for auto-proxying)”.

    So, this is because Advisor bean participates very early in application bootstrap. This is probably ok, if you wanted it, and the warning you get is not a problem, but just a reminder.