use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-integration by spring-projects.
the class IdempotentReceiverAutoProxyCreatorInitializer method initialize.
@Override
public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
List<Map<String, String>> idempotentEndpointsMapping = new ManagedList<Map<String, String>>();
for (String beanName : registry.getBeanDefinitionNames()) {
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
if (IdempotentReceiverInterceptor.class.getName().equals(beanDefinition.getBeanClassName())) {
Object value = beanDefinition.removeAttribute(IDEMPOTENT_ENDPOINTS_MAPPING);
Assert.isInstanceOf(String.class, value, "The 'mapping' of BeanDefinition 'IDEMPOTENT_ENDPOINTS_MAPPING' must be String.");
String mapping = (String) value;
String[] endpoints = StringUtils.tokenizeToStringArray(mapping, ",");
for (String endpoint : endpoints) {
Map<String, String> idempotentEndpoint = new ManagedMap<String, String>();
idempotentEndpoint.put(beanName, beanFactory.resolveEmbeddedValue(endpoint) + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX);
idempotentEndpointsMapping.add(idempotentEndpoint);
}
} else if (beanDefinition instanceof AnnotatedBeanDefinition) {
if (beanDefinition.getSource() instanceof MethodMetadata) {
MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
String annotationType = IdempotentReceiver.class.getName();
if (beanMethod.isAnnotated(annotationType)) {
Object value = beanMethod.getAnnotationAttributes(annotationType).get("value");
if (value != null) {
Class<?> returnType;
if (beanMethod instanceof StandardMethodMetadata) {
returnType = ((StandardMethodMetadata) beanMethod).getIntrospectedMethod().getReturnType();
} else {
try {
returnType = ClassUtils.forName(beanMethod.getReturnTypeName(), beanFactory.getBeanClassLoader());
} catch (ClassNotFoundException e) {
throw new CannotLoadBeanClassException(beanDefinition.getDescription(), beanName, beanMethod.getReturnTypeName(), e);
}
}
String endpoint = beanName;
if (!MessageHandler.class.isAssignableFrom(returnType)) {
/*
MessageHandler beans, populated from @Bean methods, have a complex id,
including @Configuration bean name, method name and the Messaging annotation name.
The following pattern matches the bean name, regardless of the annotation name.
*/
endpoint = beanDefinition.getFactoryBeanName() + "." + beanName + ".*" + IntegrationConfigUtils.HANDLER_ALIAS_SUFFIX;
}
String[] interceptors = (String[]) value;
for (String interceptor : interceptors) {
Map<String, String> idempotentEndpoint = new ManagedMap<String, String>();
idempotentEndpoint.put(interceptor, endpoint);
idempotentEndpointsMapping.add(idempotentEndpoint);
}
}
}
}
}
}
if (!idempotentEndpointsMapping.isEmpty()) {
BeanDefinition bd = BeanDefinitionBuilder.rootBeanDefinition(IdempotentReceiverAutoProxyCreator.class).addPropertyValue("idempotentEndpointsMapping", idempotentEndpointsMapping).getBeanDefinition();
registry.registerBeanDefinition(IDEMPOTENT_RECEIVER_AUTO_PROXY_CREATOR_BEAN_NAME, bd);
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-integration by spring-projects.
the class DefaultConfiguringBeanFactoryPostProcessor method postProcessBeanFactory.
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
if (beanFactory instanceof BeanDefinitionRegistry) {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
this.registerNullChannel(registry);
if (!beanFactory.containsBean(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME)) {
this.registerErrorChannel(registry);
}
if (!beanFactory.containsBean(IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME)) {
this.registerTaskScheduler(registry);
}
this.registerIdGeneratorConfigurer(registry);
} else if (this.logger.isWarnEnabled()) {
this.logger.warn("BeanFactory is not a BeanDefinitionRegistry. The default '" + IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME + "' and '" + IntegrationContextUtils.TASK_SCHEDULER_BEAN_NAME + "' cannot be configured." + " Also, any custom IdGenerator implementation configured in this BeanFactory" + " will not be recognized.");
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-integration by spring-projects.
the class GlobalChannelInterceptorInitializer method initialize.
@Override
public void initialize(ConfigurableListableBeanFactory beanFactory) throws BeansException {
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
for (String beanName : registry.getBeanDefinitionNames()) {
BeanDefinition beanDefinition = registry.getBeanDefinition(beanName);
if (beanDefinition instanceof AnnotatedBeanDefinition) {
AnnotationMetadata metadata = ((AnnotatedBeanDefinition) beanDefinition).getMetadata();
Map<String, Object> annotationAttributes = metadata.getAnnotationAttributes(GlobalChannelInterceptor.class.getName());
if (CollectionUtils.isEmpty(annotationAttributes) && beanDefinition.getSource() instanceof MethodMetadata) {
MethodMetadata beanMethod = (MethodMetadata) beanDefinition.getSource();
annotationAttributes = beanMethod.getAnnotationAttributes(GlobalChannelInterceptor.class.getName());
}
if (!CollectionUtils.isEmpty(annotationAttributes)) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.genericBeanDefinition(GlobalChannelInterceptorWrapper.class).addConstructorArgReference(beanName).addPropertyValue("patterns", annotationAttributes.get("patterns")).addPropertyValue("order", annotationAttributes.get("order"));
BeanDefinitionReaderUtils.registerWithGeneratedName(builder.getBeanDefinition(), registry);
}
}
}
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-integration by spring-projects.
the class StandardIntegrationFlowContext method registerBean.
@SuppressWarnings("unchecked")
private Object registerBean(Object bean, String beanName, String parentName) {
if (beanName == null) {
beanName = generateBeanName(bean, parentName);
}
BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition((Class<Object>) bean.getClass(), () -> bean).getRawBeanDefinition();
((BeanDefinitionRegistry) this.beanFactory).registerBeanDefinition(beanName, beanDefinition);
if (parentName != null) {
this.beanFactory.registerDependentBean(parentName, beanName);
}
return this.beanFactory.getBean(beanName);
}
use of org.springframework.beans.factory.support.BeanDefinitionRegistry in project spring-integration by spring-projects.
the class MockIntegrationContextCustomizer method customizeContext.
@Override
public void customizeContext(ConfigurableApplicationContext context, MergedContextConfiguration mergedConfig) {
ConfigurableListableBeanFactory beanFactory = context.getBeanFactory();
Assert.isInstanceOf(BeanDefinitionRegistry.class, beanFactory);
BeanDefinitionRegistry registry = (BeanDefinitionRegistry) beanFactory;
registry.registerBeanDefinition(MockIntegrationContext.MOCK_INTEGRATION_CONTEXT_BEAN_NAME, new RootBeanDefinition(MockIntegrationContext.class));
String endpointsInitializer = Introspector.decapitalize(IntegrationEndpointsInitializer.class.getSimpleName());
registry.registerBeanDefinition(endpointsInitializer, BeanDefinitionBuilder.genericBeanDefinition(IntegrationEndpointsInitializer.class).addConstructorArgValue(this.springIntegrationTest).getBeanDefinition());
}
Aggregations