[英]Beans created by ImportBeanDefinitionRegistrar during autoconfiguration are not eligible for all bean postprocessors
I have implemented ImportBeanDefinitionRegistrar to create bean definitions from external source.我已经实现了 ImportBeanDefinitionRegistrar 来从外部源创建 bean 定义。 It has to be registrar since I do not know in advance how many bean definitions will be created.它必须是注册器,因为我事先不知道将创建多少个 bean 定义。
When I use the registrar on my Application class like this:当我在我的 Application 类上使用注册器时:
@SpringBootApplication
@Import(GenesysRegistrar.class)
public class IntegrationServer {
...
}
everything works fine.一切正常。
I wanted to make the import automatic for every application that uses the JAR that contains the registrar so I have created following class:我想为每个使用包含注册器的 JAR 的应用程序自动导入,所以我创建了以下类:
@Configuration
@Import(GenesysRegistrar.class)
public class GenesysAutoConfiguration {
/**/
}
and registered it in META-INF/spring.factories under key org.springframework.boot.autoconfigure.EnableAutoConfiguration
.并将其注册到 META-INF/spring.factories 键下的org.springframework.boot.autoconfigure.EnableAutoConfiguration
。
Now auto-configuration works, but I get following messages in log:现在自动配置有效,但我在日志中收到以下消息:
Bean 'xxx' of type [XXX] is not eligible for getting processed by all BeanPostProcessors
What is the difference between importing the registry from aplication class and from autoconfiguration class?从应用程序类和从自动配置类导入注册表有什么区别? I have found that following post processors are created AFTER my beans:我发现在我的 bean 之后创建了以下后处理器:
methodValidationPostProcessor
persistenceExceptionTranslationPostProcessor
webServerFactoryCustomizerBeanPostProcessor
errorPageRegistrarBeanPostProcessor
I have tried to put @AutoConfigureOrder(Integer.MAX_VALUE)
on my auto-configuration class, but it does not change anything.我试图将@AutoConfigureOrder(Integer.MAX_VALUE)
放在我的自动配置类上,但它没有改变任何东西。
Any ideas how can I fix the order so beans from definitions created by my registrar are processed after all post processors?任何想法如何修复订单,以便在所有后处理器之后处理由我的注册商创建的定义中的 bean? Why Spring creates them before all post processors?为什么 Spring 在所有后处理器之前创建它们? Any why the issue does not happen when using @Import on application class?为什么在应用程序类上使用 @Import 时不会发生此问题?
Early initialized beans are dependencies injected to other bean factoy by constructor injection.早期初始化的 bean 是通过构造函数注入注入到其他 bean 工厂的依赖项。
If the bean factory uses property injection instead of construcotr injection it does not happen.如果 bean 工厂使用属性注入而不是构造注入,则不会发生。
Question is if constructor injection on factory bean is "bad practise" - have not found anything that prohibits it.问题是工厂 bean 上的构造函数注入是否是“糟糕的做法” - 没有发现任何禁止它的东西。
Created ticket to spring-boot (as it happens only during boot auto-configuraiton): Issue #20219创建了 spring-boot 的票证(因为它只在启动自动配置期间发生):问题 #20219
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.