Invalid WARN when returning a BeanDefinitionRegistryPostProcessor from within a @Configuration class [SPR-14603] #19172
Comments
Les Hazlewood commented I commented out the //@Import(MyConfiguration.class)
@Configuration
public class SomeConfiguration {
@Configuration
public static class MyConfiguration {
@Bean
public static BeanDefinitionRegistryPostProcessor myPostProcessor() {
return new MyBeanDefinitionPostProcessor();
}
}
//other non-relevant @Bean definitions here...
} This didn't work either - same WARN message. |
Juergen Hoeller commented What does your post-processor implementation class look like? The warn message suggests that the post-processor class itself is marked with |
Thomas Vahrst commented I get the same warning, when I try to define a BeanDefinitionRegistryPostProcessor as static in ConfigClassBeanDefinitionReader :
The beanClassName in the beandefinition is set to configClass' classname and later in ConfigurationClassUtils:
This seems not to be problem for 'normal' beans, but if the bean type is
|
Thomas Vahrst commented Our workaround: |
Les Hazlewood opened SPR-14603 and commented
Consider the following configuration class:
(if it matters, this class is loaded in Spring MVC and Spring Boot applications via an
@Import(MyConfiguration.class)
annotation.)This causes a WARN message to be printed as follows:
Cannot enhance @Configuration bean definition 'myPostProcessor' since its singleton instance has been created too early. The typical cause is a non-static @Bean method with a BeanDefinitionRegistryPostProcessor return type: Consider declaring such methods as 'static'.
As you can see, the method is declared as static, yet I still receive the WARN message. When I remove the
static
modifier, I still receive the same WARN message. Something is amiss.This is a problem for us because we use this code in a Spring library as well as a Spring Boot starter/plugin that we distribute to customers - when they see the WARN message, they think something is wrong, even though everything is working as expected.
Issue Links:
The text was updated successfully, but these errors were encountered: