@Bean javadoc states when BFPP is defined with non-static method, it writes a WARN-level log message.
This works out in BFPP cases, as they are not typically referenced by other @Bean methods. As a reminder, a WARN-level log message will be issued for any non-static @Bean methods having a return type assignable to BeanFactoryPostProcessor
The commit 9a43d2ec208d2e8cd0866431acf26af3529f8677 (SPR-16946, #21485) updated the logging level in ConfigurationClassEnhancer and this message shows up as INFO log.
if (logger.isInfoEnabled() &&
BeanFactoryPostProcessor.class.isAssignableFrom(beanMethod.getReturnType())) {
logger.info(String.format("@Bean method %s.%s is non-static and returns an object " +
"assignable to Spring's BeanFactoryPostProcessor interface. This will " +
"result in a failure to process annotations such as @Autowired, " +
"@Resource and @PostConstruct within the method's declaring " +
"@Configuration class. Add the 'static' modifier to this method to avoid " +
"these container lifecycle issues; see @Bean javadoc for complete details.",
beanMethod.getDeclaringClass().getSimpleName(), beanMethod.getName()));
}
So, either javadoc or log level need to be updated to match actual description and behavior.
Comment From: sbrannen
The Javadoc for @Bean is out of sync in this regard.
Thanks for pointing it out.