简体   繁体   English

在自动配置期间由 ImportBeanDefinitionRegistrar 创建的 Bean 不适用于所有 Bean 后处理器

[英]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.

相关问题 Bean 定义被 AutoConfiguration 覆盖 - Bean definition is overriden by AutoConfiguration [TYPE] 类型的 Bean 'x' 不能被所有 BeanPostProcessor 处理 - Bean 'x' of type [TYPE] is not eligible for getting processed by all BeanPostProcessors 如果一个bean由Spring管理,是否意味着所有创建的bean也必须被管理 - If one bean is managed by Spring does this mean all created beans also have to be managed 通过自动配置创建可自动连接的@Beans - Create Autowireable @Beans from autoconfiguration 自定义springboot自动配置无法检测bean - Custom springboot autoconfiguration not detecting beans 有没有办法让@Bean创建的一些bean可以区分? - Is there a way to make some beans created by @Bean distinguishable? 排除基于应用程序 yaml 文件的自动配置 bean - Exclude autoconfiguration beans based on application yaml file 没有豆有资格注射到注射点 - No bean is eligible for injection to the injection point 如果使用@Bean标签创建一个bean,那么我们可以创建两个bean。 每个applicaton如何单例 - If A bean is created using @Bean tag then we can create two beans. How is it singleton per applicatonContext @InjectMock 是否用所有其他 bean 中的模拟替换 bean? - Does @InjectMock replace the bean with a mock in all other beans?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM