Fix BeanFactoryFunctionCatalog initialization when a
BeanFactoryPostProcessor that depends on FunctionCatalog is present. On application context refresh, BeanFactoryPostProcessors are invoked before registering BeanPostProcessor(s). If a BeanFactoryPostProcessor that depends on FunctionCatalog is present, then when ContextFunctionCatalogAutoConfiguration tries to fetch all functional beans (Function/Supplier/Consumer), the creation of beans where no default constructor exists fails as AutowiredAnnotationBeanPostProcessor hasn't been registered yet. Initialing BeanFactoryFunctionCatalog on ApplicationReadyEvent delays the collection of functional beans to an even later point in the lifecycle. fixes #352 Fix test name Switch to use SmartInitializingSingleton Resolves #353
This commit is contained in:
committed by
Oleg Zhurakousky
parent
9df7455a30
commit
5256ee177c
@@ -36,7 +36,7 @@ import com.google.gson.Gson;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
import org.springframework.beans.factory.BeanFactoryAware;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.beans.factory.SmartInitializingSingleton;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
|
||||
@@ -68,6 +68,7 @@ import org.springframework.core.type.StandardMethodMetadata;
|
||||
* @author Mark Fisher
|
||||
* @author Oleg Zhurakousky
|
||||
* @author Artem Bilan
|
||||
* @author Anshul Mehra
|
||||
*/
|
||||
@Configuration
|
||||
@ConditionalOnMissingBean(FunctionCatalog.class)
|
||||
@@ -85,7 +86,7 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
|
||||
protected static class BeanFactoryFunctionCatalog
|
||||
extends AbstractComposableFunctionRegistry
|
||||
implements InitializingBean, BeanFactoryAware {
|
||||
implements SmartInitializingSingleton, BeanFactoryAware {
|
||||
|
||||
private ApplicationEventPublisher applicationEventPublisher;
|
||||
|
||||
@@ -96,18 +97,17 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
* late as possible in the lifecycle.
|
||||
*/
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public void afterPropertiesSet() throws Exception {
|
||||
public void afterSingletonsInstantiated() {
|
||||
Map<String, Supplier> supplierBeans = this.beanFactory
|
||||
.getBeansOfType(Supplier.class);
|
||||
.getBeansOfType(Supplier.class);
|
||||
Map<String, Function> functionBeans = this.beanFactory
|
||||
.getBeansOfType(Function.class);
|
||||
.getBeansOfType(Function.class);
|
||||
Map<String, Consumer> consumerBeans = this.beanFactory
|
||||
.getBeansOfType(Consumer.class);
|
||||
.getBeansOfType(Consumer.class);
|
||||
Map<String, FunctionRegistration> functionRegistrationBeans = this.beanFactory
|
||||
.getBeansOfType(FunctionRegistration.class);
|
||||
.getBeansOfType(FunctionRegistration.class);
|
||||
this.doMerge(functionRegistrationBeans, consumerBeans, supplierBeans,
|
||||
functionBeans);
|
||||
functionBeans);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -227,7 +227,6 @@ public class ContextFunctionCatalogAutoConfiguration {
|
||||
registrations.forEach(registration -> register(registration,
|
||||
targets.get(registration.getTarget())));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class PreferGsonOrMissingJacksonCondition extends AnyNestedCondition {
|
||||
|
||||
Reference in New Issue
Block a user